第二章 例题2-7

#include<stdio.h>
int main(void)
{
    int i,n,sum;

    printf("Enter n:");
    scanf("%d",&n);
    sum=0;
    for(i=1;i<=n;i++){
        sum=sum+i;
    }
    printf("Sum of numbers from 1 to %d is %d\n",n,sum);

    return 0;
}

posted @ 2013-10-03 22:51  七颜℡  阅读(87)  评论(0编辑  收藏  举报