(100 pts) Write a program that implements the following functions. long factoria
ID: 642519 • Letter: #
Question
Explanation / Answer
a)
#include <iostream>
#include<stdio.h>
using namespace std;
double exponential(double x,int n)
{
float sum = 1.0f; // initialize sum of series
for (int i = n - 1; i > 0; --i )
sum = 1 + x * sum / i;
return sum;
}
int main()
{
int n = 10;
double x = 1.0f;
cout<<"e^x = "<<exponential(x,n);
return 0;
}
b)
#include <iostream>
#include<stdio.h>
using namespace std;
long factorial(int n)
{
if(n==1)
return 1;
else
return n*factorial(n-1);
}
int main()
{
int n = 5;
cout<<"n! = "<<factorial(n);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.