代码如下:
//计算1*2*3+3*4*5+5*6*7+...+99*100*101的值
#include<stdio.h>
int main() {
long i;
long term, sum = 0;
for (i = 1; i <= 99;i+=2) {
term = i*(i + 1) * (i + 2);
sum = sum + term;
printf("term=%ld*(%ld + 1) * (%ld + 2)\n",i,i,i);
printf("sum=%ld\n",sum);
printf("\n");
}
printf("sum=%ld\n",sum);
}
程序运行结果如下: