Read float and double by scan()
Use %e, %f, or %g for float. Use %le, %lf, or %lg for double.
#include <stdio.h>
main()
{
float x;
double y;
scanf("%f%lf", &x, &y);
printf("x=%f\ny=%f\n", x, y);
printf("x=%e\ny=%e\n", x, y);
printf("x=%g\ny=%g\n", x, y);
}
input is
47.403 -38.30026452e5
prints
x=47.304001
y=-3830026.452000
x=4.730400e+01
y=-3.830026e+06
x=47.304
y=-3.83003e+06
This is program
pg81.c
.
Previous slide
Next slide
Back to first slide
View graphic version