Write a program that displays ex for a non negative number x. the number x will
ID: 3633386 • Letter: W
Question
Write a program that displays ex for a non negative number x. the number x will come from user input. it is sufficient to use 10 as a maximum number for n. The function factorial should have one integer parameter (n) and return one integer(n!). the function factorial should not have any output statements. the main function should call the function factorial and should do all of the printing.The function factorial should not have any output satements. The main function should call the function factorial and should do all the printing.
Also the program i'm using is borland c++.
Explanation / Answer
Dear,
Here is the code
//Header file section
#include
#include
int factorial(int num);
using namespace std;
void main()
{
//variable declaration
double expo,x,fact,sum=0,n;
//inputting x value
cout<<"enter value of x:";
cin>>x;
//calculating e^x
n=0;
for(int i=0;i<=100;i++)
{
fact=factorial(i);
sum=sum+(pow(x,i)/fact);
}//end for
//outputting value of e^x
cout<<"e^x using library function:"< cout<<"e^x value :"<
//pause system for a while
system("pause");
}//end main
int factorial(int num)
{
int fact=1;
if(num==0)
return fact;
else
{ for(int j=num;j>0;j--)
fact=fact*j;
return fact;
}
}
Hope this will help you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.