#include <stdio.h>
#include <math.h>
int main()
{
float i=5.4, j=5.6;
printf("round of %f is %f
", i, round(i));
printf("round of %f is %f
", j, round(j));
return 0;
}
#include <math.h>
float val = 37.777779;
float rounded_down = floorf(val * 100) / 100; /* Result: 37.77 */
float nearest = roundf(val * 100) / 100; /* Result: 37.78 */
float rounded_up = ceilf(val * 100) / 100; /* Result: 37.78 */
#include <stdio.h>
int main (){
float a;
printf("
Enter a real number here please: ");
scanf("%f",&a);
printf("
Printing Number with different precision: ");
printf("
Number default precision: %f", a);
printf("
Number in (0 d.p.): %.0f", a);
printf("
Number in (1 d.p.): %.1f", a);
printf("
Number in (2 d.p.): %.2f", a);
printf("
Number in (3 d.p.): %.3f", a);
printf("
Number in (3 d.p.): %.4f", a);
return 0;
}