Value of the function F(x) = 1 + 2/x + 3/x2 + 4/x3+...

Problem Statement
For a function F(x),

     F(x) = 1 + 2/x + 3/x2 + 4/x3+...

write a function float EvaluateFunc(float x, int n) where x > 1 and evaluate the function F(x) up to n terms.


#include<stdio.h> float evaluatefun(float x,float n); int main() { float x,n,y; printf("enter the value of x and number of terms resp. \n"); scanf("%f %f",&x,&n); y=evaluatefun(x,n); printf("the value of sum is %f \n",y); return 0; } float evaluatefun(float x,float n) { float sum,i,term; term=1.0; sum=1.0; for(i=2.0;i<=n;i++) { term=term*i/((i-1)*x); sum=sum+term; } return sum; }

No comments:

Post a Comment