C语言累加求和源程序参考: 1. 用for语句实现: #include Int main(void) { int sum=0,i,n; printf(“Piease Input a number n:”); scanf(“n=d”,&n); for(i=0;i<=n;i++) { sum+=I; } printf(“sum=%d\n”,sum); return 0; } 2. 用while语句实现: #include int main(void) { int sum=0,i=0,n; printf(“Piease Input a number n:”); scanf(“n=d”,&n); while(i<=n) { sum+=I; i++; } printf(“sum=%d\n”,sum); return 0; } 3. 用do-while语句实现: #include int main(void) { int sum=0,i=0,n; printf(“Piease Input a number n:”); scanf(“n=d”,&n); do { sum+=I; i++; } while(i<=n); printf(“sum=%d\n”,sum); return 0; } 本文来源:https://www.wddqw.com/doc/0f2e08405fbfc77da369b14d.html