126. C Program to Compute the 1/1+1/3+1/5+1/7+……………+1/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 1/1+1/3+1/5+1/7+……………+1/n upto nth term.
- where The nth term is the user input.
- Computing the given series is easy by Using the simple for loop condition.
Here is the code
#include <stdio.h>
int main(void)
{
int i,N;
float sum;
//To store value of N
printf("Enter the value of N: \n13");
scanf("%d",&N);
//Set sum by 0
sum=0.0f;
//Compute sum of the series
for(i=1;i<=N;i+=2)
sum = sum + ((float)1/(float)i);
//To print the sum of series
printf("\nSum of the series of 1/1 + 1/3 + 1/5 + 1/7 +...+ 1/n is: %f\n",sum);
return 0;
}