1149 Summing Consecutive Integers

SemiColon
By -
0
URI Online Judge | 1149

Summing Consecutive Integers

Write an algorithm to read a value A and a value N. Print the sum of N numbers from A (inclusive). While N is negative or ZERO, a new N (only N) must be read. All input values are in the same line.

Input

The input contains only integer values, ​​can be positive or negative.

Output

The output contains only an integer value.
Input SampleOutput Sample
3 27
3 -1 0 -2 27

 Solution:

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

Tags:

Post a Comment

0Comments

Post a Comment (0)