In this section you will learn how to write the C Program to find the sum of N Natural Number.
For Eg. Find the sum of first 5 natural number
1+2+3+4+5 = 15
Now lets see the C Program to find the sum of N Natural Number
Program
/* Exp No 3: display natural number and find sum */ #include <stdio.h> int main() { int n,i,sum=0; printf("Enter How many terms to be display\n"); scanf("%d",&n); /* display series and find sum */ for(i=1; i<=n; i++) { printf("%4d",i); sum = sum+i; } printf("\n Sum of natural number = %d \n",sum); return 0; }
Output :-