C Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - Find Output of Program (Q.No. 9)
9.
What will be the output of the program?
#include<stdio.h>
int main()
{
float a = 0.7;
if(0.7 > a)
printf("Hi\n");
else
printf("Hello\n");
return 0;
}
Answer: Option
Explanation:
if(0.7 > a) here a is a float variable and 0.7 is a double constant. The double constant 0.7 is greater than the float variable a. Hence the if condition is satisfied and it prints 'Hi'
Example:
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;
}
Output:
0.7000000000 0.6999999881
Discussion:
20 comments Page 1 of 2.
Sangz said:
3 years ago
Here, a is float value a=0.7 we should convert the float value into an integer it becomes o (ex:2.5 float value when to convert this into integer it becomes 2 like this they done).
If statement is 0.7>a .when converted our float value 0.7 to integer value 0 hence condition satisfied 0.7>a ie is 0.7>0 when the condition is satisfied it print hi.
If statement is 0.7>a .when converted our float value 0.7 to integer value 0 hence condition satisfied 0.7>a ie is 0.7>0 when the condition is satisfied it print hi.
(1)
Gaurav said:
6 years ago
As per my knowledge, it's.
#include <stdio.h>
main()
{
if (sizeof(int) > -2)
printf("True");
else
printf("False");
}
#include <stdio.h>
main()
{
if (sizeof(int) > -2)
printf("True");
else
printf("False");
}
Kaira said:
6 years ago
How can we understand that 0.7 is double not float? Please explain me.
(2)
Divya said:
7 years ago
Here not mention 0.7 has double? Then how can I take it as double maybe it is float also?
(1)
Saneh sharma said:
7 years ago
please explain this.
#include <stdio.h>
int main()
{
char a='\101';
printf("%c",a);
}
#include <stdio.h>
int main()
{
char a='\101';
printf("%c",a);
}
Jason said:
8 years ago
What happens if the 0.7 is replaced by 0.6? or simply by Experiment (gcc on Ubuntu) shows a different story than the theory (double to float).
Swati said:
9 years ago
When we place 0.8 instead of 0.7 then prints Hi. Why?
Please elaborate.
Please elaborate.
Naresh kalluri said:
9 years ago
They are not given (0.7 >= a)
So the condition is false.
It will prints the else statement in that hello message will be printed.
So the condition is false.
It will prints the else statement in that hello message will be printed.
Pratibha said:
1 decade ago
#include<stdio.h>
int main()
{
float a=0.7;
printf("%10f %10f\n",0.7, a);
return 0;
}
This gives output: 0.70000 0.70000
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;}
0.7000000000 0.6999999881.
Then what %f differs from %f?
int main()
{
float a=0.7;
printf("%10f %10f\n",0.7, a);
return 0;
}
This gives output: 0.70000 0.70000
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;}
0.7000000000 0.6999999881.
Then what %f differs from %f?
(1)
Ayush Rai said:
1 decade ago
It doesn't give the same output for 0.66 neither for 0.8 even in your compiler. And when I tried printing the digits it came out to be opposite in trend both times 0.66!>a neither is 0.8. See for yourself and please explain.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers