Evaluate a function F(x) = 1 + 2/x^1 + 3/x^2 + 4/x^3 +...

Problem Statement 
For the function
F(x) = 1 + 2/x1 + 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 n 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; printf("terms are 1.0 "); for(i=2.0;i<=n;i++) { term=term*i/((i-1)*x); printf(" %f",term); sum=sum+term; } return sum; }       
  

No comments:

Post a Comment