Program to find the sum of n natural numbers in c language.

#include<stdio.h>
#include<conio.h>
void main()
{
 int n,sum=0;
 printf("enter no. where you want to add of natural numbers =");
 scanf("%d",&n);
 for(int i=1; i<=n; i++)
 {
 sum=sum +i;
 }
 printf("the sum of %d natural numbers is=%d",n,sum);
 getch();
 }

■》 Output->

enter no. where you want to add of natural numbers =>10

the sum of 10 natural numbers is=> 55

Comments

Popular posts from this blog

Introduction of java Programming language.

Stack data structure.