Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to write a program that implements the following functions and need it wi

ID: 3554290 • Letter: I

Question

I need to write a program that implements the following functions and need it within the time limit.

long factorial(int n)

double exponent(double x, int n)

This is the equation http://puu.sh/82RsC.png

Read the value of n and x from the user and compute the first n terms of e^x using the function exponent. Print the result returned by the function and compare it with the value obtained by calling the math library function exp. When you increase the value of n your result should get closer to the result of exp.

Sample execution of the program is given below:

Enter n and x

20 2.1

Approximation = 8.1753222282

Exact = 8.1661699126

Thank you so much for the help!

Explanation / Answer

#include<stdio.h>

#include<iostream.h>

#include<math.h>

// factorial ..........

long factorial (long n)

{

if(n==1 ) return 1;

return factorial (n-1) * (n-1);

}

// exponent ......

double exponent (double x , int n)

{

for(int i=1; i<=n ;i++)

x=x*x;

return x;

}

void main()

{

int n;

double x;

cout<<"Enter x and n";

cin>>n>>x;

cout<<"Approax value ="<<exp(n);

cout<<"Exact value "<<exponent(2.71,n);              /////////////value of e =2.7

}