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;
}
3.00
3.15
3.2
3
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.

Atul sharma said:   1 decade ago
It mean there are all 2 decimal values which is going to print and. 1 mean there is one value after decimal.

Dinesh said:   1 decade ago
No it's wrong sharma. 2 means it takes 2 empty spaces before printing a value on the screen.

Shekhar said:   1 decade ago
3.2 is the answer.

3 means it will take 3 decimal values into consideration.

Raeesa said:   7 years ago
What will be the output of printf("%f",(float)9.5)?

Sriram said:   1 decade ago
What is the purpose of 2 in "2. 1f"?


Post your comments here:

Your comments will be displayed after verification.