diff options
author | Michael Abed <michaelabed@gmail.com> | 2012-03-05 14:28:10 -0500 |
---|---|---|
committer | Michael Abed <michaelabed@gmail.com> | 2012-03-05 14:28:10 -0500 |
commit | 1c03e941f1015c48917ddc603d84b134eb705f10 (patch) | |
tree | d89b07d63a12b5542882328c679bb76fb23a5f63 | |
parent | f2566da91396bc07356601794fd5db858a78f1f3 (diff) | |
download | ec327-lab2-1c03e941f1015c48917ddc603d84b134eb705f10.tar.gz ec327-lab2-1c03e941f1015c48917ddc603d84b134eb705f10.tar.bz2 ec327-lab2-1c03e941f1015c48917ddc603d84b134eb705f10.zip |
-rw-r--r-- | Q1.cpp | 3 | ||||
-rw-r--r-- | Q2.cpp | 3 | ||||
-rw-r--r-- | Q3a.cpp | 18 | ||||
-rw-r--r-- | Q3b.cpp | 10 |
4 files changed, 9 insertions, 25 deletions
@@ -10,7 +10,7 @@ int main() double input; double sq, mysq; - do { // + do { cout << "Enter a number (negative to quit)" << endl; cout << ">> "; cin >> input; @@ -21,7 +21,6 @@ int main() cout << "sqrt(" << input << ") = " << sq << endl; cout << "sqrt and mysqrt differ by " << abs(sq - mysq) << endl; } - } while (input >= 0); return 0; @@ -15,8 +15,7 @@ int main(int argc, const char *argv[]) cout << ">> "; cin >> input; - if (argc > 1) - write_data(input, 1000, 500); + write_data(input, 1000, 500); mean = get_mean(input); min = get_minimum(input); @@ -8,7 +8,7 @@ int gcd(int m, int n); int gcd(int m, int n) { if (m <= 0 || n <= 0) - return 0; + return 0; // invalid if (m % n == 0) return n; @@ -18,19 +18,7 @@ int gcd(int m, int n) int main(int argc, const char *argv[]) { - int m, n; - int result; - cout << "Enter 2 numbers to calculate the greatest common divisor (0 to quit)" << endl; - do { - cout << ">> "; - cin >> m >> n; - if (m <= 0 || n <= 0) { - cout << "Please input positive numbers (0 to quit)" << endl; - } else { - result = gcd(m, n); - cout << "gcd(" << m << ", " << n << ") = " << result << endl; - } - } while (m != 0 || n != 0); - + cout << "gcd(24,16) = " << gcd(24,16) << endl; + cout << "gcd(255, 25) = " << gcd(255,25) << endl; return 0; } @@ -15,15 +15,13 @@ double series(int n) int main(int argc, const char *argv[]) { - int x; - cout << "enter a number to see the sum of the series (0 to quit)" << endl; + long x; + cout << "enter a number to see the sum of the series (negative to quit)" << endl; do { cout << ">> "; cin >> x; - if (x <= 0) - cout << "Please enter a positive number (0 to quit)" << endl; - else + if (x >= 0) cout << "series(" << x << ") = " << series(x) << endl; - } while (x != 0); + } while (x >= 0); return 0; } |