求1+2+3+……+n之和

xiaoxiao2021-02-28  22

#include<stdio.h> main() { int i,n,sum; printf("Input n:"); while(scanf("%d",&n)!=EOF) { sum=0; for(i=1;i<=n;i++) { sum=sum+i; } printf("sum=%d\n",sum); printf("Input n:"); } return 0; }

运行结果:

转载请注明原文地址: https://www.6miu.com/read-1449997.html

最新回复(0)