Linux under the C Language Magic matrix program

Source: Internet
Author: User
Tags printf linux

#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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.