Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
|
|
harm(n) which
computes the sum of the first n terms in the harmonic series:
\[\frac{1}{1} + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \cdots +
\frac{1}{n}\]
For example, harm(1) should return 1, and
harm(2) should return 1.5.
Warning: Be careful about the type of an expression. For example,
1/3 evaluates to 0 of type int!
pow(2, 5) should return 32, and
pow(3, 4) should return 81. No loops!
#include <iostream>
using namespace std;
double pow(double, int);
int main()
{
double x;
int n;
cout << "Enter x and n: ";
cin >> x >> n;
cout << "x^n is " << pow(x,n) << endl;
return 0;
}
// Define pow: it must be recursive!
~/bin/submit -c=IC210 -p=hw24 hw.cpp