#include <stdio.h> #include<math.h> int main() { float a, b, c; int id; scanf("%d;%f,%f,%f", &id, &a, &b, &c); a = roundf(a * 100) / 100; b = roundf(b * 100) / 100; c = roundf(c * 100) / 100; printf("The each subject score of No. %d is %.2f, %.2f, %.2f.", id, a, b, c); return 0; }
roundf()函数四舍五入,先放大,再舍入更精准,其实也是无奈之举。下面这个总有四舍五入过不了╮(╯▽╰)╭
#include <stdio.h> int main() { float a, b, c; int id; scanf("%d;%f,%f,%f", &id, &a, &b, &c); printf("The each subject score of No. %d is %.2f, %.2f, %.2f.", id, a, b, c); return 0; }