Search This Blog

Calculate the Sum of Natural Numbers | C programming

Calculate the Sum of Natural Numbers

 

Problem :

Read an integer value, which is  a Natural number. Find the sum of every numbers up to N.


Input

The input file contains an integer N.

Output

Print the sum of the numbers up to N.




Solution

In C language:

#include<stdio.h>

int main()
{

    int N,i,sum;
    scanf("%d",&N);


    sum = 0;
    for(i=1;i<=N;i++){
        sum = sum + i;
    }


    printf("%d\n",sum);
    return 0;

} 




Discussion: 

If you don't understand anything, ask in comment box. 

No comments

Powered by Blogger.