C program that demonstrates function assignment

      
assign one function assignment to another program in c


Source code

#include<stdio.h>
#include<math.h>

double fact(double a)
{
 	double	f=1.0;
 	for(;a>0;a--)
 			f*=a;
 	return	f;
}
double exp_term(double b, double x)
{
 return(pow(x,b)/fact(b));
}
double	by_term(double b, double x)
{
	 return(1/pow(x,b));
}
double	sum(double f(double,double), int m,	int	n)
 {
	 int	K;
	 double	s = 0.0;
	 double	x;
	 printf("\n ENTER THE VALUE OF x :");
	 scanf("%lf",&x);
	 for(K=m; K<=n;++K)
	 	s+=f(K,x);
	 return	s;
 }
 int	main()
 {
  	printf("\n SUM	OF COMPUTATION	1: %lf:",sum(exp_term,0,3));
 	printf("\n SUM	OF COMPUTATION	2: %lf",sum(by_term,0,4));
 	return	0;
 }
 


edit-code-image

Sample Test cases:

1.  ENTER THE VALUE OF x : 0
    SUM  OF COMPUTATION  1: 1.000000:
    ENTER THE VALUE OF x : 1
    SUM    OF COMPUTATION  2: 5.000000

2. ENTER THE VALUE OF x : 1
   SUM OF COMPUTATION  1: 2.666667:
   ENTER THE VALUE OF x : 2
   SUM  OF COMPUTATION  2: 1.937500

Explanation for function Assignment:

Step 1:
Step 2:
Step 3:
Step 4:

More Insights:

Explore More