From a4e822de2827c122ad2a7db79984becc021c2513 Mon Sep 17 00:00:00 2001 From: Yana Blashchishina Date: Thu, 1 Feb 2024 23:00:33 -0800 Subject: exercise 8 completed --- InClassExercise8/InClassExercise8/NestedLoops.cpp | 44 +++++++++++++++++++++++ InClassExercise8/InClassExercise8/program.cpp | 28 ++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) (limited to 'InClassExercise8') 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 + + +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 + +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 -- cgit v1.2.3