Menu

[solved] – Question 93042

Consider the code below for calculating the value of e (Euler’s number/constant used in mathematics). It solves the same problem as discussed in the lecture but it does it differently. In the ith iteration it calculates the value of 1/i! and adds it to the result.

main_program{
int n; cin >> n;

double result = 0;
int i=__;

repeat(n){
// calculate 1/i!
int t=1;
double term = 1;
repeat(i){
term = term/t;
t = t + 1;
}
result = result + term;
i = i + 1;
}
cout << result << endl;

}

What should i be initialized to?

How many division operations does the above code do for n=10?

How many division operations did the code discussed in the lecture do for n=10?

Expert Answer


OR


Leave a Reply

Your email address will not be published. Required fields are marked *