Problem Statement
For a function F(x),
#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("\n 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;
}
For a function F(x),
F(x) = 1 + 2/x + 3/x2 + 4/x3 +...
write a c program to print terms of this series
then calculate sum of all the terms
write a c program to print terms of this series
then calculate sum of all the 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("\n 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