CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <iomanip>
int main() {
// Declare and initialize the matrix dimensions,
// then indexes used for the spiral, and our
// current direction.
int n, m, j = 0, k = 0;
enum {down, right, up, left} d = down;
std::cout << "Enter the row and column size: " << std::flush;
std::cin >> n >> m;
std::cout << std::endl;
// Verify the matrix dimensions are reasonable and if not
// default them.
if (n < 0 || n > 30)
n = 5;
if (m < 0 || m > 30)
m = 5;
// Declare and initialize array.
int ary[30][30];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ary[i][j] = 0;
// For the number of cells in the matrix, store the
// value and figure out the next cell.
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run