116. C Program to Compute the 1+3+5+7+9+ …………….+n series.
How does this program work?
- This program is used to compute the sum of series for the given order.
- Here we are going to find the series for odd numbers upto nth term.
- The nth term is the user input.
- Computing the given series is easy by Using the simple for loop condition.
Here is the code
//1+3+5+7+9+ ……………….+n
#include <stdio.h>
int main(void)
{
int n,sum = 0;
printf("Enter series of number\n");
scanf("%d",&n);
for ( int i=1; i<= n; i+=2)
{
sum=i+sum;
}
printf("sum of series odd numbers upto %d is %d",n,sum);
return 0;
}