C Programming - Input / Output - Discussion

Discussion Forum : Input / Output - Find Output of Program (Q.No. 5)
What will be the output of the program ?

int main()
    float a=3.15529;
    printf("%2.1f\n", a);
    return 0;
Answer: Option

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

15 comments Page 2 of 2.

Shekhar said:   1 decade ago
3.2 is the answer.

3 means it will take 3 decimal values into consideration.

Ash said:   1 decade ago
int main()
float a=3.15529;
printf("%3.1f\n", a);
return 0;

What is the answer for this?

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

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.

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.