C Programming
Computer Programming

Program in c to Calculate the Sum of first n Natural Numbers



Write a Program in c to Calculate the Sum of first n Natural Numbers

\* C Program to to Calculate the Sum of first n Natural Numbers *\

# include < stdio.h >
int   main( )
{

int   n, i, sum=0  ;
printf(" How many natural number you want to calculate : ") ;
scanf("%d ", & n) ;
i = 1 ;
while (   i   <=   n  ;
{

sum= sum + i ;
i = i + 1 ;

}
printf("\n Sum of Natural Numbers are : ") ;
scanf("%d ", sum) ;
return ( 0 ) ;

}

Output of Program :

Output of Program in C to Calculate the Sum of first n Natural Numbers