C program to display the n terms of natural number and their sum
#include
<stdio.h>
#include<conio.h>
main()
{
int i,n,sum=0;
printf("Enter how many terms : ");
scanf("%d",&n);
printf("\nThe first %d natural numbers
are:\n",n);
for(i=1;i<=n;i++)
{
printf("%d ",i);
sum+=i;
}
printf("\nThe Sum of natural numbers
upto %d terms : %d \n",n,sum);
getch();
}
No comments:
Post a Comment