From a69cd34091836c632c3268e646ac5a85fb9f8175 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 29 Oct 2021 10:27:03 +0300 Subject: Added my solutions to Sem. 03 exercises --- .../Solutions Sem. 03/10. Spiral_Numbers.cpp | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Year 1/Programming introduction/Solutions Sem. 03/10. Spiral_Numbers.cpp (limited to 'Year 1/Programming introduction/Solutions Sem. 03/10. Spiral_Numbers.cpp') diff --git a/Year 1/Programming introduction/Solutions Sem. 03/10. Spiral_Numbers.cpp b/Year 1/Programming introduction/Solutions Sem. 03/10. Spiral_Numbers.cpp new file mode 100644 index 0000000..66e5e70 --- /dev/null +++ b/Year 1/Programming introduction/Solutions Sem. 03/10. Spiral_Numbers.cpp @@ -0,0 +1,24 @@ +#include + +using namespace std; + +int main() +{ + int n; + cin >> n; + + for (int row = 0; row < n; row++) + { + int previous = row + 1; + for (int col = 0; col < n; col++) + { + if (col == 0) + cout << previous << " "; + else if (col % 2 == 0) + cout << (previous += row * 2 + 1) << " "; + else + cout << (previous += (n -row -1) * 2 + 1) << " "; + } + cout << endl; + } +} -- cgit v1.3.1-26-gb76a