5752101 [rkeene@sledge /home/rkeene/personal/school/comp-sci-ii/kitten]$ cat -n finde.cpp
 1 #include <iostream>
 2 using namespace std;
 3 
 4 int factorial(int i) {
 5     int m, ret=i;
 6     for (m=(i-1);m>0;m--) {
 7         ret*=m;
 8     }
 9     return(ret);
10 }
11 
12 // e=1+(1/1!)+(1/2!)+...+(1/n!)
13 int main(void) {
14     int n=5, i;
15     float e=1.0;
16 
17     cout << "Enter number of iterations (n) [5]? ";
18     cin >> n;
19     for (i=1;i<=n;i++) {
20         e+=(1.0/factorial(i));
21     }
22     cout << "e = " << e << "\n";
23 }
5752102 [rkeene@sledge /home/rkeene/personal/school/comp-sci-ii/kitten]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2002-09-12 16:17:32