Friday, May 10, 2019

C programming : Program to find the sum of natural numbers


/* Program to find the sum of natural numbers in C programming langu */

#include<stdio.h>
#include<conio.h>
void main ()
{
int i,n,sum=0;
clrscr();
printf ("\n Enter the value of n ");
scanf ("%d",&n);
for (i=1;i<=n;i++)
{
sum=sum+i;
}
printf ("\n The sum of n natural numbers is %d",sum);
getch();
}

Output

Enter the value of n
10
The sum of n natural numbers is 55
 
Now the output will be seen as:

 
 

1 comment:

Function

FUNCTION C enables programmer to break up a program into segments commonly known as functions, each of which can be written more or...