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 2 of 2.
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?
Mallesh said:
1 decade ago
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;
}
Explanations please.
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;
}
Explanations please.
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".
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;
}
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;
}
Ketaki said:
1 decade ago
How the value comes 0.699999818?
Rahul said:
1 decade ago
@sundar.
Good explaination. !
Good explaination. !
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
M.MANOJI said:
1 decade ago
How i know this 0.7 is double ? and why i can not assume that 0.7 is float value ? is there any default assumption for this declaration ?
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
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers