+ 3

In c programming, how to roundoff a floating point number as per the wish of the user.

for example i have a number a=1.3124, the user have to enter a number by himself upto which he wants to round off a number after decimal. if he enter n=2 the the no. printing in screen should be a=1.31 two digit after decimal.

8th Feb 2018, 3:00 PM
Aman Kumar Jain
Aman Kumar Jain - avatar
1 Réponse
+ 16
Try this int n; //no of decimals u want float no= 3.456789; scanf("%d",&n); printf("%.*f",n,no);
8th Feb 2018, 3:56 PM
Frost
Frost - avatar