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