C program to find sum of first n numbers

#include<stdio.h>

int main()

{

    int n,i;

    printf("enter the number \n");

    scanf("%d",&n);
    int sum=0;
    for(i=1;i<=n;i=i+1)

    {

       sum=sum+i;

    }

    printf("The sum of first %d number is: %d",n,sum);

}

Output:     
               


Comments