计算从1加到n的和:
#include<stdio.h> int main() { int i,sum=0,n; scanf("%d",&n); sum=(1+n)*n/2; printf("%d\n",sum); return 0; }