-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
49 lines (45 loc) · 917 Bytes
/
main.c
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<stdio.h>
#include<conio.h>
#include <windows.h>
int main()
{
int col, row, i, size, totalSize;
printf("Enter size of magic box: ");
scanf("%d", &size);
totalSize = size * size;
for(i = 1; i <= totalSize; i++)
{
if(i == 1)
{
row = 1;
col = (size + 1) / 2;
}
else if(((i-1) % size) == 0)
{
row++;
}
else
{
row--;
col--;
if(row == 0)
row = size;
if(col == 0)
col = size;
}
gotoxy(col, row);
printf("%d",i);
}
printf("\ntotal magic square size %d\n", totalSize);
return 0;
}
void gotoxy( int column, int line )
{
COORD coord;
coord.X = column;
coord.Y = line;
SetConsoleCursorPosition(
GetStdHandle( STD_OUTPUT_HANDLE ),
coord
);
}