C Programming - Input / Output - Discussion
Discussion Forum : Input / Output - Find Output of Program (Q.No. 5)
5.
What will be the output of the program ?
#include<stdio.h>
int main()
{
float a=3.15529;
printf("%2.1f\n", a);
return 0;
}
Answer: Option
Explanation:
float a=3.15529; The variable a is declared as an float data type and initialized to value 3.15529;
printf("%2.1f\n", a); The precision specifier tells .1f tells the printf function to place only one number after the .(dot).
Hence the output is 3.2
Discussion:
15 comments Page 2 of 2.
Anitha said:
8 years ago
int main()
{
float a=3.15529;
printf("%2.1f\n", a);
return 0;
}
2 here represents the 2positions to consider so we take 3.155, since it is 5 we round it as 3.2 and print the value is it.
Am I right?
Someone explain it if I'm wrong.
{
float a=3.15529;
printf("%2.1f\n", a);
return 0;
}
2 here represents the 2positions to consider so we take 3.155, since it is 5 we round it as 3.2 and print the value is it.
Am I right?
Someone explain it if I'm wrong.
Samarth Goyal said:
8 years ago
int main()
{
float a=3.15529;
printf("%b.1f\n", a);
return 0;
}
Varying b simply indents the result. What really matters or rather what will affect the output is the digit after the decimal.
say b=3, in that case the output will be printed upto 3 decimal places.
{
float a=3.15529;
printf("%b.1f\n", a);
return 0;
}
Varying b simply indents the result. What really matters or rather what will affect the output is the digit after the decimal.
say b=3, in that case the output will be printed upto 3 decimal places.
Nishtha Khare said:
8 years ago
Main()
{
float a=0.7;
if(a<0.7)
printf("c");
else
printf("c++");
}
Why the output of this program will be "c"?
{
float a=0.7;
if(a<0.7)
printf("c");
else
printf("c++");
}
Why the output of this program will be "c"?
Raeesa said:
8 years ago
What will be the output of printf("%f",(float)9.5)?
Palak said:
5 years ago
Wht if i dont want the decmal point to change from for eg : 3.09 to 3.1 when i am printing only one decimal point.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers