#include <stdio.h>
#include <stdlib.h>
int main ()
{
int a[31][31], I, J, M, n, p = 0;
while (P = = 0)
{
System ("clear");
printf ("Please enter an odd number not greater than 30:");
scanf ("%d", &m);
if (M!= 0 && m <= && m% 2!= 0)
Break
}
for (i = 1; I <= m; i++)
for (j = 1; j <= M; j + +)
A[I][J] = 0;
j = i/2 + 1;
A[1][J] = 1;
for (n = 2; n <= m * m; n++)
{
i = i-1;
j = j + 1;
if (I < 1 && j > m)
{i = i + 2;
j = j-1;}
Else
{
if (I < 1) i = m;
if (J > m) j = 1;
}
if (a[i][j] = = 0)
A[I][J] = n;
Else
{
i = i + 2;
j = j-1;
A[I][J] = n;
}
}
System ("clear");
printf ("This number of Rubik's Cube array is: \ n");
for (i = 1; I <= m; i+
COLOR: #0000cc ">+)
{
for (j = 1; J <= m:j++)
printf ("%4d", A[i][j]);
printf ("\ n");
}
return 0;
}
This program is compiled under Linux
Gcc-wall-g filename.c-o filename
Compiler warning Option-wal
Its role is to let GCC compile the process to generate more warning information
The role of the-G option is used when debugging with GDB, so if you want to debug this option must be added, otherwise it can not be debugged.
The-o option is to produce a renamed executable (for example, Magiccube.c-o magic, so that a magic executable file is generated, without adding a file named A.out)