+ 1

how to set width of float when user have to input the float value? FOR C LANGUAGE

If i enter 3.14159 in console window but i want the program to give output as 3.14

19th Dec 2018, 5:34 PM
Bilal Khan
Bilal Khan - avatar
3 Answers
+ 3
printf("%5.2f \n", 3.14159); Please indicate language by adding the tag to your question Please remove the tags input and output and replace by float as tag
19th Dec 2018, 5:57 PM
Gordon
Gordon - avatar
+ 2
You must use printf with %.nf After point n is number of decimals and f means float. Example for printing three decimals: float f = 1.23456; printf("%.3f",f);
19th Dec 2018, 7:48 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 1
thank you sir
19th Dec 2018, 6:10 PM
Bilal Khan
Bilal Khan - avatar