diff options
Diffstat (limited to 'project')
| -rw-r--r-- | project/NestedLoops.cpp | 54 | ||||
| -rw-r--r-- | project/NestedLoops.h | 6 | ||||
| -rw-r--r-- | project/program.cpp | 12 |
3 files changed, 67 insertions, 5 deletions
diff --git a/project/NestedLoops.cpp b/project/NestedLoops.cpp index e451ce2..fdb59e2 100644 --- a/project/NestedLoops.cpp +++ b/project/NestedLoops.cpp @@ -1,3 +1,55 @@ #include "NestedLoops.h" -#include <iostream>
\ No newline at end of file +#include <iostream> + +using std::cout; +using std::cin; +using std::endl; + +void NestedForLoop(size_t n, size_t m) +{ + for (int i = 0; i < n; ++i) + { + for (int j = 0; j < m; ++j) + { + cout << "i = " << i << ", j = " << j << endl; + cout << i * j << endl; + + } + } +} + + +void NestedWhileLoop(size_t n, size_t m) +{ + n = 0; + while (n < 4) + { + m = 0; + while (m < 3) + { + cout << "n = " << n << ", m = " << m << endl; + m++; + } + cout << endl; + n++; + } +} + + +void NestedDoWhileLoop(size_t n, size_t m) +{ + n = 1; + do + { + m = 1; + do + { + cout << n * m << " "; + ++m; + + } while (m <= 3); + cout << endl; + n++; + } while (n <=3 ); +} diff --git a/project/NestedLoops.h b/project/NestedLoops.h index d14b549..2f467d0 100644 --- a/project/NestedLoops.h +++ b/project/NestedLoops.h @@ -1,11 +1,11 @@ #ifndef NestedLoops #define NestedLoops -void ForLoop(size_t n); +void NestedForLoop(size_t n, size_t m); -void WhileLoop(size_t n); +void NestedWhileLoop(size_t n, size_t m); -void DoWhileLoop(size_t n); +void NestedDoWhileLoop(size_t n, size_t m); #endif NestedLoops diff --git a/project/program.cpp b/project/program.cpp index 982e803..fd7c5cf 100644 --- a/project/program.cpp +++ b/project/program.cpp @@ -6,10 +6,20 @@ #include <iostream> #include "NestedLoops.h" +using std::cout; +using std::cin; +using std::endl; + + + int main() { + int n = 2; + int m = 3; - + //NestedForLoop(n, m); + //NestedWhileLoop(n, m); + NestedDoWhileLoop(n, m); return 0; }
\ No newline at end of file |