Name: ____________________________________________________ Alpha:
_____________ Section: ________
Describe help received: _________________________________________________________________
See the bottom for how to submit your work.
Due: Before 0800 on next class day
| Output: |
double harm(int 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.
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;
}
// TODO: Define pow: it must be recursive!
Submit to the submission server (due: 0800 on the next class day)
~/bin/submit -c=IC210 -p=hw35 hw.cpp
Bring to class