【杭电 OJ】1001 Sum Problem

Output

For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.

 

 

Sample Input

 

1

100

 

Sample Output

 

1

 

5050

 

 

#include 
#include 
#include 

int main()
{
    int i, n, sum = 0;

        /*if(scanf("%d", &n) != EOF)
            {for(i = 1; i <= n; i++)
                sum += i;
            printf("%d\n", sum);}*/

    while(scanf("%d", &n) != EOF)
    {
        sum = 0;
        for(i = 1; i <= n; i++)
            sum += i;
        printf("%d\n\n", sum);
    }
    return 0;
}

 

 

 

你可能感兴趣的:(【杭电 OJ】1001 Sum Problem)