0
2.8kviews
Write a program to calculate sum of series:

½ - ¾ + 5/6 – 7/8 …….up to n terms.

1 Answer
0
172views

Algorithm:

  • Start.

  • Declare variables i, j and Sum.

  • Read values of numbers.

  • Set i = 1 and j = 1.

  • Increment i and set j = j + 2.

  • Add numbers and assign the result to sum.

  • Sum = Sum + (float)(j)/(j+2) – (float)(j)/(j+1).

  • Display sum.

  • Stop.

Program:

#include<stdio.h>
#include<conio.h>

int main(){
int i, j, n;
float sum = 0;

printf("\n Enter the Value of n:");
scanf("%d",&n);

for(i=1, j=1; i<=n; i++, j=j+2){
sum = sum+(float)(j)/(j+1)-(float)(j)/(j+1);
}

printf("sum= %f",sum);
}

Output:

Enter the Value of n: 5

Sum = 0.60833

Please log in to add an answer.