PROGRAM TO DISPLAY N NATURAL NUMBERS AND THEIR SUM

/*PROGRAM TO DISPLAY N NATURAL NUMBERS AND THEIR SUM*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
clrscr();
printf(“Enter the range of natural numbers: “);
scanf(“%d”,&n);
printf(“Natural numbers upto %d are:\n”,n);
for(i=1;i<=n;i++)
{
printf(“%d\t”,i);
sum=sum+i;
}
printf(“\n”);
printf(“\nSum of first %d natural numbers is: %d”,n,sum);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *