Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Programming introduction / Solutions Sem. 03 / 10. Spiral_Numbers.cpp
diff options
context:
space:
mode:
1 files changed, 24 insertions, 0 deletions
-rw-r--r--Year 1/Programming introduction/Solutions Sem. 03/10. Spiral_Numbers.cpp24
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 <iostream>
+
+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;
+ }
+}