#include"stdio.h"
intmain()
{
doublesum=0;//用double的目的是提高精度
doubleitem=0;
inti;
for(i=1;i<=99;i+=2)//步长2,各项头数是相接的,
{
item=i*(i+1)*(i+2)*1.0;
sum+=item;
}
printf("1*2*3+3*4*5+...+99*100*101=%.0lf\n",sum);
return0;
}
扩展资料
C语言编程计算1/1-1/2+1/3-1/4+……1/100的值
#include
#include
intmain()
{
inti,n=100;
doublesum1=0,sum2=0,sum;
for(i=1;i<100;i=i+2)
sum1=sum1+(1.0/i);
for(i=2;i<=100;i=i+2)
sum2=sum2-(1.0/i);
sum=sum1+sum2;
printf("%lf",sum);
system("pause");
return0;
}