No older revisions available
No older revisions available
~cpp
#include <iostream>
using namespace std;
int main()
{
int input, count, row, col;
int **mabang;
int i, j;
cout << "몇 열 ? : ";
cin >> input;
while (input % 2 == 0)
{
cout << "다시 입력 ? : ";
cin >> input;
}
mabang = new int*[input];
for (i = 0; i < input; i++)
mabang[i] = new int[input];
for (i = 0; i < input; i++)
for (j = 0; j < input; j++)
mabang[i][j] = 0;
row = 0; col = input / 2;
count = 0;
while (count != input * input)
{
mabang[row][col]=++count;
if (mabang[(row - 1 == -1 ? input - 1 : row - 1)][(col + 1 == input) ? 0 : col + 1] == 0)
row--, col++;
else
row++;
if (row == -1)
row = input - 1;
if (col == input)
col = 0;
}
for (i = 0; i < input; i++)
{
for (int j = 0; j < input; j++)
cout << mabang[i][j] << "\t";
cout << endl;
}
for (i = 0; i < input; i++)
delete [] mabang[i];
delete [] mabang;
return 0;
}