0
2.7kviews
Write a program to calculate sum of series:
written 7.7 years ago by | modified 2.2 years ago by |
½ - ¾ + 5/6 – 7/8 …….up to n terms.
ADD COMMENT
EDIT
1 Answer
written 7.7 years ago by | modified 2.2 years ago by |
½ - ¾ + 5/6 – 7/8 …….up to n terms.
written 7.7 years ago by |
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