使用 float
#include <stdio.h>
int main() {
int id;
float c, math, english;
scanf("%d;%f,%f,%f", &id, &c, &math, &english);
printf("The each subject score of No. %d is %.2f, %.2f, %.2f.\n", id, c, math, english);
return 0;
}
使用 double
#include <stdio.h>
int main() {
int id;
double c, math, english;
scanf("%d;%lf,%lf,%lf", &id, &c, &math, &english);
c = (int)(c*100+0.5)/100.0;
math = (int)(math*100+0.5)/100.0;
english = (int)(english*100+0.5)/100.0;
printf("The each subject score of No. %d is %.2lf, %.2lf, %.2lf.\n", id, c, math, english);
return 0;
}