diff options
| -rw-r--r-- | project/NestedLoops.cpp | 33 | ||||
| -rw-r--r-- | project/program.cpp | 17 |
2 files changed, 31 insertions, 19 deletions
diff --git a/project/NestedLoops.cpp b/project/NestedLoops.cpp index fdb59e2..65fac24 100644 --- a/project/NestedLoops.cpp +++ b/project/NestedLoops.cpp @@ -13,43 +13,44 @@ void NestedForLoop(size_t n, size_t m) for (int j = 0; j < m; ++j) { cout << "i = " << i << ", j = " << j << endl; - cout << i * j << endl; + cout << "the product of the incrementers are; " << i * j << endl; } } } - void NestedWhileLoop(size_t n, size_t m) { - n = 0; - while (n < 4) + int i = 0; + while (i < n) { - m = 0; - while (m < 3) + int j = 0; + while (j < m) { - cout << "n = " << n << ", m = " << m << endl; - m++; + cout << "n = " << i << ", m = " << j << endl; + cout << "the product of the incrementers are; " << i * j << endl; + j++; } cout << endl; - n++; + i++; } } void NestedDoWhileLoop(size_t n, size_t m) { - n = 1; + int i = 0; do { - m = 1; + int j = 0; do { - cout << n * m << " "; - ++m; + cout << "n = " << i << ", m = " << j << endl; + cout << "the product of the incrementers are; " << i * j << endl; + j++; - } while (m <= 3); + } while (j <= m); cout << endl; - n++; - } while (n <=3 ); + i++; + } while (i <= n ); } diff --git a/project/program.cpp b/project/program.cpp index fd7c5cf..da7a2b7 100644 --- a/project/program.cpp +++ b/project/program.cpp @@ -10,16 +10,27 @@ using std::cout; using std::cin; using std::endl; - +//test int main() { int n = 2; int m = 3; - //NestedForLoop(n, m); - //NestedWhileLoop(n, m); + cout << "Nested for loop for bounds of n = 2 and m = 3" << endl; + cout << endl; + NestedForLoop(n, m); + cout << endl; + + cout << "Nested while loop for bounds of n = 2 and m = 3" << endl; + cout << endl; + NestedWhileLoop(n, m); + cout << endl; + + cout << "Nested while loop for bounds of n = 2 and m = 3" << endl; + cout << endl; NestedDoWhileLoop(n, m); + cout << endl; return 0; }
\ No newline at end of file |