C program to find the summation of n numbers

In this program we will use for loop to calculate the summation of n numbers. Code for the task is given below.

Code for C program to find the summation of n numbers

#include <stdio.h>
#include <conio.h>
int main()
{
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
for (i = 1; i <= n; ++i)
{
sum += i;
}
printf("Sum = %d", sum);
return 0;
}

Output

Enter a positive integer: 25
Sum = 325

Read: C program to print the number of days in a month using switch statements


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment