#include<stdio.h> //三位小数,我就直接先让它放大1000倍 floattest(float a) { int b = a * 1000; int tmp = 10; while (tmp >= 10) { tmp = b % 10; } if (tmp < 5) { a = (float)(b - tmp) / 1000; return a; } else { a = (float)(b + 10 - tmp) / 1000; return a; } } intmain() { float a = 80.635; float b = 80.630; printf("%.2f\n", test(a)); printf("%.2f\n", test(b)); return0; }
附上全代码:
#include<stdio.h> floattest(float a) { int b = a * 1000; int tmp = 10; while (tmp >= 10) { tmp = b % 10; } if (tmp < 5) { a = (float)(b - tmp) / 1000; return a; } else { a = (float)(b + 10 - tmp) / 1000; return a; } } intmain() { float a = 0; float b = 0; float c = 0; int n = 0; scanf("%d;%f,%f,%f", &n, &a, &b, &c); printf("The each subject score of No. %d is %.2f, %.2f, %.2f.", n, test(a), test(b), test(c)); return0; }