C program to display sum of first n natural numbers using for loop
************************************************************
C program to display sum of first n natural numbers
***********************************************************/
#include<stdio.h>
void main()
{
int i,num,sum=0;
printf("** OUTPUT**\n");
printf("How many natural number you wants to display\n");
scanf("%d",&num);
printf("First N natural numbers are\n");
for(i=0;i<=num;i++)
{
printf("%d\n",i);
sum=sum+i;
}
printf("The sum of first N natural numbers is: %d\n",sum);
printf("End of program");
}
** OUTPUT**
How many natural number you wants to display
12
First N natural numbers are
0
1
2
3
4
5
6
7
8
9
10
11
12
The sum of first N natural numbers is: 78
End of program
0 टिप्पण्या
कृपया तुमच्या प्रियजनांना लेख शेअर करा आणि तुमचा अभिप्राय जरूर नोंदवा. 🙏 🙏