Answer:
// here is code in C.
#include <stdio.h>
// function that calculate factorial of a number recursively
long int fact_num(int num)
{
if (num >= 1)
return num*fact_num(num-1);
else
return 1;
}
// function that calculate power of a number recursively
int num_pow(int b, int p)
{
if (p != 0)
return (b*num_pow(b, p-1));
else
return 1;
}
//edoublepowerx function
float edoublepowerx(int x){
int i;
float tot_sum = 1.0;
for(i = 0; i <= 10;i++ ){
tot_sum = tot_sum + (num_pow(2,i)*num_pow(x,i))/fact_num(i);
}
return tot_sum;
}
// driver function
void main()
{
// variables
float x,res;
printf("Please enter the value of x : ");
//read the value of x
scanf("%f",&x);
// call the function to calculate the value
res = edoublepowerx(x);
// print the result
printf("e^2x = %f",res);
}
Explanation:
In the main function, first read the value of "x" from user.Then call the function edoublepowerx() with parameter "x".In this function, total of the equation is calculated by summing all the term one by one with the help of for loop. In the for loop,"(num_pow(2,i)*num_pow(x,i))/fact_num(i)" for each value of "i". here num_pow(), calculate the power of number recursively and fact_num() calculated the factorial of a numbers recursively.After the loop ends edoublepowerx() will return the value to the equation.
Output:
Please enter the value of x : 3
e^2x = 383.000000