Thursday 26 January 2012

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>
void 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( );
}

No comments:

Post a Comment