diff options
| author | Yana Blashchishina <[email protected]> | 2024-02-01 23:00:33 -0800 |
|---|---|---|
| committer | Yana Blashchishina <[email protected]> | 2024-02-01 23:00:33 -0800 |
| commit | a4e822de2827c122ad2a7db79984becc021c2513 (patch) | |
| tree | 6b8728ca38cafab8f3bf19eb95e7e68ed28e1d9d /InClassExercise8 | |
| parent | header done (diff) | |
| download | in-class-exercise-8-yanablash-a4e822de2827c122ad2a7db79984becc021c2513.tar.xz in-class-exercise-8-yanablash-a4e822de2827c122ad2a7db79984becc021c2513.zip | |
Diffstat (limited to 'InClassExercise8')
| -rw-r--r-- | InClassExercise8/InClassExercise8/NestedLoops.cpp | 44 | ||||
| -rw-r--r-- | InClassExercise8/InClassExercise8/program.cpp | 28 |
2 files changed, 71 insertions, 1 deletions
diff --git a/InClassExercise8/InClassExercise8/NestedLoops.cpp b/InClassExercise8/InClassExercise8/NestedLoops.cpp index e69de29..9c3ea03 100644 --- a/InClassExercise8/InClassExercise8/NestedLoops.cpp +++ b/InClassExercise8/InClassExercise8/NestedLoops.cpp @@ -0,0 +1,44 @@ +#include "NestedLoops.h" +#include <iostream> + + +using std::cout; +using std::endl; + +void NestedForLoop(size_t n, size_t m) { + for (size_t i = 0; i <= n; ++i) { + for (size_t j = 0; j <= m; ++j) { + cout << i * j << " "; + } + cout << endl; + } + +} + + +void NestedWhileLoop(size_t n, size_t m) { + size_t i = 0; + while (i <= n) { + size_t j = 0; + while (j <= m) { + cout << i * j << " "; + ++j; + } + cout << endl; + ++i; + } +} + + +void NestedDoWhileLoop(size_t n, size_t m) { + size_t i = 0; + do { + size_t j = 0; + do { + cout << i * j << " "; + ++j; + } while (j <= m); + cout << endl; + ++i; + } while (i <= n); +}
\ No newline at end of file diff --git a/InClassExercise8/InClassExercise8/program.cpp b/InClassExercise8/InClassExercise8/program.cpp index 10dd62e..1824bfe 100644 --- a/InClassExercise8/InClassExercise8/program.cpp +++ b/InClassExercise8/InClassExercise8/program.cpp @@ -1,4 +1,30 @@ //Name: Yana Blashchishina //Date:01/29/2024 //Class: CST116 -//Assignment:In Class Exercise 8
\ No newline at end of file +//Assignment:In Class Exercise 8 + + +#include "NestedLoops.h" +#include <iostream> + +using std::cout; + +int main() { + + size_t n = 5; + size_t m = 10; + + cout << "Nested For Loop: "; + NestedForLoop(n, m); + + cout << "Nested While Loop: "; + NestedWhileLoop(n, m); + + cout << "Nested Do While Loop: "; + NestedDoWhileLoop(n, m); + + + + + return 0; +}
\ No newline at end of file |