Wednesday, February 18, 2015

C program to find the sum of series 1 2 4 5 7 8

C program to find the sum of series 1/2+4/5+7/8+......

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


void main()
{
int i,n;
clrscr();
float sum=0,x,a=1;

printf("1/2+4/5+7/8+......");
printf("

How many terms(ex: 1,2,3...n)?");
scanf("%d",&n);


for(i=0;i<n;++i)
{
x=a/(a+1);
sum+=x;
a+=3;
}

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

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.