Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why doesn't format specifier allocate places according to the value given in "Printf" ?

+1 vote
asked Mar 25, 2018 by Mohanram
PROGARAM :

float A; A=106.10; printf("Value of A is %5.2f", A);

OUTPUT: Value of A is 106.10

QUESTION: Even if I have given, "%2.2f" instead of "%5.2f", I'm getting the same output.

The value of A will not be displayed/changed according to the format specifier ?

2 Answers

0 votes
answered Mar 25, 2018 by anonymous

you can write

printf("value of A is %f",5.2*A)

this is correct

0 votes
answered Mar 27, 2018 by gmjjatin (140 points)
edited Mar 27, 2018 by gmjjatin
in ("%X.Yf" ,A )  -

1. X - determines space occupied by all digits (including decimal) of A

2. Y-  determines space occupied by right hand digit of A.

 case 1.  when X<= actual no. of  digits

             no effect

case 2 .   when  X> actual no. of digits
             displayed digit will be shifted accordingly   i.e.  it will have spaces to left of digit so that

              sum of total space to left of decimal = X.

similarly for RH digits of decimal.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...