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