参考代码如下:
#include <stdio.h> int main() { int a, b, c; scanf("%d %d %d", &a, &b, &c); int suma = 0; int sumb = 0; double sumc = 0; double sum = 0; int i; for (i = 1; i <= a; i++) suma += i; for (i = 1; i <= b; i++) sumb += i * i; for (i = 1; i <= c; i++) sumc += 1.0 / i; //注意此处用1.0/i !! sum = suma + sumb + sumc; printf("%.2lf", sum); return 0; }
0.0分
0 人评分