Find out the output of the program | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

Find out the output of the program

#include <stdio.h> int main() { int a=10, b=20; if(a=b) { printf("Easy"); } else { printf("Hard"); } return 0; }

21st Jul 2023, 4:27 AM
Ajay Raj
Ajay Raj - avatar
11 Respostas
+ 4
Ajay Raj .. If you want comparison with two values then use comparison operator "==" instead of the assignment operator "=". For fex the error. Change this comparison operator "==". (`a==b`),instead of this(`a=b`)..
21st Jul 2023, 5:01 AM
Darpan kesharwanišŸ‡®šŸ‡³[InactivešŸ“š]
Darpan kesharwanišŸ‡®šŸ‡³[InactivešŸ“š] - avatar
+ 2
DHEEVIKA SURESH First decide Easy or Hard? because you have given 2 different answers.
23rd Jul 2023, 6:37 PM
AĶ¢J
AĶ¢J - avatar
+ 1
in you code you assign a to be not comparing it your code should look like #include <stdio.h> int main() { int a=10, b=20; //condition statement if(a==b) { printf("Easy"); } else { printf("Hard"); } return 0; }
23rd Jul 2023, 9:39 AM
Alpha chiwangu
0
Why not to get self in Code Playground?
21st Jul 2023, 4:59 AM
AĶ¢J
AĶ¢J - avatar
0
If b is zero, only the else condition will be executed, otherwise the if condition as shown in the description. The reason for this is due to a behavior called "Cohersion and Down casting" whereby a variable gets converted from a type to another possible type in this case from [int to boolean] To prevent this, you have to use the right operator for example the equality checker's Operator (==) instead of the assignment operator (=)
21st Jul 2023, 5:08 AM
White Shadow
White Shadow - avatar
0
Dear Ajay Raj In this code, the header file stdio.h is included the preprocessor mixes the code of header file in our program file. Now, the line of control goes to the int main() function and then the line of control jumps to the initialised variable where a=10 and b=20, Here a using (=) operator which is used to initialise the variable not for comparing variable. Then, the line of control jumps to the if statement where a condition is given that if a is initialised to b then print "Easy" otherwise print "Hard" right. Here, (a=b) means a is initialised to b where in a variable the value of b variable is put which is true. Therefore, the output of this code is "Easy". Output: Easy Thanks for asking this question!
21st Jul 2023, 5:23 PM
Amrit Kesharwani
Amrit Kesharwani - avatar
0
use '==' in line 5 for comparison of two values
22nd Jul 2023, 10:38 AM
Alhaaz
Alhaaz - avatar
0
Easy
22nd Jul 2023, 6:31 PM
DHEEVIKA SURESH
DHEEVIKA SURESH - avatar
0
Find out the output of the program #include <stdio.h> int main() { int a=10, b=20; if(a=b) { printf("Easy"); } else { printf("Hard"); } return 0; } Output Easy
23rd Jul 2023, 6:41 PM
DHEEVIKA SURESH
DHEEVIKA SURESH - avatar
0
in you code you assign a to be not comparing it your code should look like #include <stdio.h> int main() { int a=10, b=20; //condition statement if(a==b) { printf("Easy"); } else { printf("Hard"); } return 0; } output Hard
23rd Jul 2023, 6:41 PM
DHEEVIKA SURESH
DHEEVIKA SURESH - avatar
0
Program 1 #include <stdio.h> int main() { int a=10, b=20; if(a=b) { printf("Easy"); } else { printf("Hard"); } return 0; } Program 2 #include <stdio.h> int main() { int a=10, b=20; //condition statement if(a==b) { printf("Easy"); } else { printf("Hard"); } return 0; } Program 1 assign the value of b to a. Program 2 compare tha value of a and b..
23rd Jul 2023, 6:43 PM
DHEEVIKA SURESH
DHEEVIKA SURESH - avatar