0
why it not prints expected output?
hello guys I am learning C (beginner). please help me with this problem why it not printing 3.14? #include <stdio.h> #define print printf int main(int argc, char *argv[]) { print("%8.2f",3.14567); } outout : 3.15 and what is the meaning of 8 (wide means what? )
7 odpowiedzi
+ 4
Jan Markus in this case width will be illustrated with leading white spaces.
If it would have been "%08.2" then width would be represented by leading zeros.
https://code.sololearn.com/cO3KHBy9fQeJ/?ref=app
+ 3
"%8.2f" means print a floating point number which is at leas 8 wide and have a precision of 2
Means 3.1456 will be made 3.14 { precision of 2 }
And to maintain the width of 8, required spaces would be added in front {4 in this case as 3.14 is already 4 wide}
+ 3
The right answer is 3.14567near to 3.15 so if u need 3.14 take less than 3.14500 than you will get your answer....
+ 1
yes
0
I understood what is "8" in my case but still unable to understand why it is printing 3.15 instead of 3.14
in above stack thread they said they will round nearest even number but here is it rounding odd?? got confused 🙁
0
answer:because of approximation method in maths ..........
here in my code bit you get the answer with example ...read comments in the code .....
https://code.sololearn.com/cXBhLYI9M5r0/?ref=app
0
Jan Markus sir
printf("%.2f",3.14500) ;
here it also printing 3.15 😭
how ?