#include <stdio.h> int main(void) { long sum=0L; int count =0; int i,j;这个地方必须把它全局声明。这样才不会出现一个叫做 :只允许在 C99 模式下使用‘for’循环初始化声明 的错误。 printf(" Enter the number of integers you wnat to sum:"); scanf("%d",&count); for(i=1;i<=count;i++) { sum=0L; for (j=1;j<=i;j++) sum+=j; printf(" %d %ld",i,sum); } system("pause"); return 0; }
#include <stdio.h> int main(void) { long sum=0L; int count =0; int i,j=1; printf(" Enter the number of integers you wnat to sum:"); scanf("%d",&count); for (i=1;i<=count;i++) { sum=1L; printf(" 1"); while (j<i) { sum+=++j; printf("+%d",j); } printf("=%ld ",sum); } system("pause"); return 0; }