Subscribe

RSS Feed (xml)

Wednesday, July 29, 2009

Write a C program to Calculate the sum of the series sum=1+1/x+1/x2+1/x3+...........+1/xn

#include(stdio.h)
#include(conio.h)
#include(math.h)
int main( )
{
int i, x, n;
float sum, p;
clrscr( );
printf("Enter the base value 'x':");
scanf("%d", &x);
printf("\nEnter the power value 'n':");
scanf(" %d", &n);
sum=1;
for( i=1; i<=n ; i++)
{
p=pow(x, i);
sum=sum+(1/p);
}
printf("\nSum of the series: %f", sum);
getch( );
return 0;
}

Note:- if u have any douts regarding this program, please feel free to contact.

7 comments: