Solved programming problem

Sum of 0 to Nth Number in C.

Source code

#include<stdio.h>

int main()

{

    int n,i,sum=0;

    printf("Please Enter A Number: ");

    scanf("%d",&n);

    for(i=0;i<=n;i++)

    {

        sum=sum+i;

    }

    printf("
Sum of 0 to %d is: %d
",n,sum);

    return 0;

}

Output

Please Enter A Number:10

Sum of 0 to 10 is:55

Join the discussion

Add your comment