summaryrefslogtreecommitdiff
path: root/Q3b.cpp
diff options
context:
space:
mode:
authorMichael Abed <michaelabed@gmail.com>2012-03-02 14:19:26 -0500
committerMichael Abed <michaelabed@gmail.com>2012-03-02 14:19:26 -0500
commit973562e3bbffbe2502649ce30d55e7cc6cbc6c3c (patch)
treed6fe33a799e9ca0034e9e98b6b155b0706937f83 /Q3b.cpp
parentc2391ab3040f0ce641eb77b2fe5a693b9f6e2444 (diff)
downloadec327-lab2-973562e3bbffbe2502649ce30d55e7cc6cbc6c3c.tar.gz
ec327-lab2-973562e3bbffbe2502649ce30d55e7cc6cbc6c3c.tar.bz2
ec327-lab2-973562e3bbffbe2502649ce30d55e7cc6cbc6c3c.zip
i did things
Diffstat (limited to 'Q3b.cpp')
-rw-r--r--Q3b.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/Q3b.cpp b/Q3b.cpp
new file mode 100644
index 0000000..08676c8
--- /dev/null
+++ b/Q3b.cpp
@@ -0,0 +1,29 @@
+
+#include <iostream>
+
+using namespace std;
+
+double series(int n);
+
+double series(int n)
+{
+ if (n <= 0)
+ return 0;
+ else
+ return (double) (n/(2.0*n+1.0)) + series(n-1);
+}
+
+int main(int argc, const char *argv[])
+{
+ int x;
+ cout << "enter a number to see the sum of the series (0 to quit)" << endl;
+ do {
+ cout << ">> ";
+ cin >> x;
+ if (x <= 0)
+ cout << "Please enter a positive number (0 to quit)" << endl;
+ else
+ cout << "series(" << x << ") = " << series(x) << endl;
+ } while (x != 0);
+ return 0;
+}