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

Help I need to know how to start and some explanation pretty please Lenguaje C W

ID: 3791410 • Letter: H

Question

Help I need to know how to start and some explanation pretty please Lenguaje C Write a program that implements the following functions iteratively (no recursion). double factorial(int n) double exponent double x, int n) The functions implemented should follow below guidelines factorial: Computes n n x (n 1) x... x 1 erponent: Computes the sum of first n terms of er using the following approximation. You can use pour0 and factorial unctions in your exponent function In main use arac and argu read the value of n and z from the user and compute and print the approximation of er for all values up to n using the function erponent. Print the results as a table as shown below. Also, print the exact value of e using the math library function erp0. When you increase the value of i your result should get closer to the result of erp. Name your program assign3.c Sample execution of the program is given below. First param- eter is n and second parameter is z You need to use functions atoi and atof0 in stdlib.h to convert strings to integer and double respectively. fox01 assi 10 2.2 Approximation o 1.0000000000 1 3.20000000000 5.6200000000 3 7.3946666667 4 8.3707333333 5 8.8002026667 6 8.9576747556 7 9.0071659835 9.0207760712 9 9.0241029815 10 9.0248349018 Exact Value 9.0250134994

Explanation / Answer


// C code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <unistd.h>

double factorial(int n)
{
int i;
int fact = 1;
for(i=1; i<=n; ++i)
{
fact *= i; // factorial = factorial*i;
}
return fact;
}

void exponential(double x, int n)
{
double sum = 0;
int i = 0;
printf(" i Approximation ");
printf("-------------------------------------- ");
for (int i = 0; i <= n; ++i)
{
sum = sum + pow(x,i)/factorial(i);
printf(" %d %0.10lf ",i,sum);
}
}

int main(int argc, char const *argv[])
{
if (argc < 2)
{
printf("Value of n and x not found ");
return 0;
}

int n = atoi(argv[1]);
double x = atof(argv[2]);

exponential(x,n);
printf("Exact Value = %0.10f ",exp(x));
return 0;
}

/*
output:

i Approximation
--------------------------------------
0 1.0000000000
1 3.2000000000
2 5.6200000000
3 7.3946666667
4 8.3707333333
5 8.8002026667
6 8.9576747556
7 9.0071659835
8 9.0207760712
9 9.0241029815
10 9.0248349018
Exact Value = 9.0250134994

*/