Sale!

# Computer Programming II Assignment 3

\$22.00

Category:

CS 1713
Introduction to Computer Programming II
Assignment 3

1. (100 pts) 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 × (n − 1) × . . . × 1
• exponent: Computes the sum of first n terms of e
x using the following approximation.
f(x, n) = e
x =
∑n
i=0
x
i
i!
=
x
0
0! +
x
1
1! +
x
2
2! + . . . +
x
n
n!
You can use pow() and f actorial() functions in your exponent function.
In main() use argc and argv read the value of n and x from the user and compute and print
the approximation of e
x
for all values up to n using the function exponent. Print the results
as a table as shown below. Also, print the exact value of e
x using the math library function
exp(). When you increase the value of i your result should get closer to the result of exp.
Name your program assign3.c Sample execution of the program is given below. First parameter is n and second parameter is x. You need to use functions atoi() and atof() in stdlib.h
to convert strings to integer and double respectively.
fox01> assign3 10 2.2
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
Submit your program electronically using the blackboard system
The program you submit should be your own work. Cheating will be reported to office of academic
integrity. Both the copier and copiee will be held responsible.

## Reviews

There are no reviews yet.