C Program to Sum of First N natural Number

This c program prompts the user to enter the value of n, then it calculates the sum of the first N natural numbers using a for loop, and finally, it prints the result.

You can run this program, enter a value for N, and it will display the sum of the first N natural numbers.

Program :

#include<stdio.h>
#include<conio.h>
main()
{
int n,sum,i;
i=1;
sum=0;
printf(“Enter How many numbers do you want to add up to : “);
scanf(“%d”,&n);
while(i<=n)
{
sum=sum+i;
i=i+1;
}
printf(“%d is the Sum of first %d numbers.”,sum,n);
}

Output :

Leave a Comment

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

Shopping Basket
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
Verified by MonsterInsights