Posts

Showing posts from March, 2021

Find remainder Codechef problem solution in C language with logic

Image
 First discuss some topic  Types of Loops : Primarily, there are three types of loop in c language: 1.While loop 2.do-while loop 3.for loop We will look into this one by one While Loop While(condition is true) { // Code                    // The block keeps executing as long as the condition is true // Code } Here the code --> #include <stdio.h>  int main() { // Read the number of test cases. int T; scanf("%d", &T); while (T--) { // Read the input a, b int a, b; scanf("%d %d", &a, &b); // Compute the ans. // Complete this line. int ans = a%b; printf("%d\n", ans); } return 0; } So here the logic is we need find remainder so we use a%b its give the remaider when a%b==0 its means a is proper multiplier of b or we can say b is proper divisor of a.                                              Thank you

Number mirror Codechef problem Solution in C languages with logic

Image
Let first we some topic Receiving input from the user In order to take input from the user and assign it to a variable, we use scanf function. The syntax for using scanf: scanf("%d",&a); // %d for integer // %f for real constant // %c for character & is the “address of” operator and it means that the supplied value should be copied to the address which is indicated by variable i. Here the code--> #include <stdio.h> int main(void) {     int n;     scanf("%d",&n);     printf("%d",n); return 0; } The logic is very easy that first we declare a integer then take a input through user by using scanf then print that variable.                                                Thank You 

Enormous Input test Codechef Solution in C language with logic

Image
 Let first we discuss some topic. Increment and decrement operators i++  (i is increased by 1) i--  (i is decreased by 1) printf(“—i=%d”,--i); This first decrements i and then prints it printf(“i--=%d”,i--); This first prints i and then decrements it 1. +++ operators does not exists => Important 2. += is compound assignment operator just like -=, *=, /= & %= =>Also important here the code--> #include <stdio.h>  int main() { int n, k; scanf("%d %d", &n, &k); int ans = 0; for (int i = 0; i < n; i++) { int t; scanf("%d", &t); if (t % k == 0) { ans++; } } printf("%d\n", ans); return 0; } and then use custom input,  used data provided by codechef in question. So now discuss the logic we only need to remove the (" using namespace std; ") because  “ using namespace std ”  means in programming languages  we  use  the  namespace  named  std . “ std ” is an abbreviation for  standard . So that  means  we  use

ATM CodeChef soultion in C language with logic

Image
first discuss this points because it related to problem Primarily there are 3 types of constant: 1.    Integer constant =    -1,8,9 2.    Real constant =     -322.9,2.5,7.0 3.    Character constant = ‘a’,’$’,’@’(must be enclosed within single inverted commas) For print we use printf("%d",integer_constant); //%d for integer constant  //%f for real constant //%c for character constant So here the code--> #include <stdio.h> int main() { int X; float Y; scanf("%d %f",&X,&Y); if(X%5!=0){     printf("%.2f",Y); } else if(X+0.5>Y){     printf("%.2f",Y); } else{     printf("%.2f",Y-(X+0.5)); } return 0; } so the logic is first we declare variable then we get input by user as you see above through scanf. then their is condition that the atm machine would accept only multiple of five so we use conditional statement that if its not multiple of five and the amount is bigger then Y then its show bal