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.
Sundar said:
1 decade ago
@M.Manoji
0.7 --> The compiler will assume it as a double value by default.
If you want the compiler should treat 0.7 as float value then you have specify the value along with a postfix character 'f'.
Example: 0.7f
/* Example Program executed in Turbo C */
#include
int main()
{
printf("%d, %d, %d", sizeof(0.5), sizeof(double), sizeof(3.14f));
return 0;
}
//Output: 8 8 4
0.7 --> The compiler will assume it as a double value by default.
If you want the compiler should treat 0.7 as float value then you have specify the value along with a postfix character 'f'.
Example: 0.7f
/* Example Program executed in Turbo C */
#include
int main()
{
printf("%d, %d, %d", sizeof(0.5), sizeof(double), sizeof(3.14f));
return 0;
}
//Output: 8 8 4
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)
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.
Naresh N said:
1 decade ago
#include <stdio.h>
main()
{
if (sizeof(int) > -1)
printf("True");
else
printf("False");
}
Can any one explain me why answer is false?
main()
{
if (sizeof(int) > -1)
printf("True");
else
printf("False");
}
Can any one explain me why answer is false?
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");
}
Alisha said:
1 decade ago
please give me explanation of your example
#include<stdio.h>
int main()
{
float a=0.7;
printf("% 10f %f\n",0.7,a);
return 0;
}
please explain printf statement
#include<stdio.h>
int main()
{
float a=0.7;
printf("% 10f %f\n",0.7,a);
return 0;
}
please explain printf statement
Govind verma said:
1 decade ago
What will be the output.
int main()
{
flaot a=3.5;
if(a==3.5)
printf("tru");
else
printf("false");
return 0;
}
int main()
{
flaot a=3.5;
if(a==3.5)
printf("tru");
else
printf("false");
return 0;
}
S.R.RAMBABU said:
1 decade ago
The given value is 0.7 and the value of a is 0.7 the symbol > it defines both the symbol equalto(=) and (>) so the output is "hi".
Pon said:
1 decade ago
Please give me explanation of your example
#include<stdio.h>
int main()
{
float a=0.7;
printf("% 10f %f\n",0.7,a);
return 0;
}
#include<stdio.h>
int main()
{
float a=0.7;
printf("% 10f %f\n",0.7,a);
return 0;
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers