链接http://acm.swust.edu.cn/problem/0042/
自然数求和公式http://baike.baidu.com/view/1518948.htm
#include <stdio.h> int main() { double sum(int a,int b,double c); int a,b; double c; scanf("%d %d %lf",&a,&b,&c); printf("%.2lf\n",sum(a,b,c)); return 0; } double sum(int a,int b,double c) { int i; int sum_1=0,sum_2=0; double sum_3=0; sum_1=a*(a+1)/2; for(i=1;i<=b;i++) { sum_2+=i*i; } for(i=1;i<=c;i++) { sum_3+=1/(double)i; } return sum_1+sum_2+sum_3; }
时间: 2024-12-08 05:23:52