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.
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).
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 ?
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.
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.
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);
}
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)
Swati said:
9 years ago
When we place 0.8 instead of 0.7 then prints Hi. Why?
Please elaborate.
Please elaborate.
Kaira said:
6 years ago
How can we understand that 0.7 is double not float? Please explain me.
(2)
Ketaki said:
1 decade ago
How the value comes 0.699999818?
Rahul said:
1 decade ago
@sundar.
Good explaination. !
Good explaination. !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers