글
#include <stdio.h>
int matrix[201][201];
int count=1;
void fillCount(int x, int y)
{
if(x != 0) //오른쪽 위로 진행
{
while(x>=0 && y>=0)
{
if (matrix[x][y] ==1)
matrix[x][y] = count++;
x--;
y++;
}
}
else //왼쪽 아래로 진행
{
while(x>=0 && y>=0)
{
if (matrix[x][y] ==1)
matrix[x][y] = count++;
x++;
y--;
}
}
}
int main()
{
int n, i, j;
int num;
scanf("%d", &n);
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
matrix[i][j] = 1;
}
}
for(num=0; num < (2*n)-1; num++)
{
if(num%2 == 0)
{
fillCount(0,num);
}
else
{
fillCount(num,0);
}
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
printf("%d ",matrix[i][j]);
}
printf("\n");
}
return 0;
}
'Programming Language' 카테고리의 다른 글
freopen example (0) | 2015.11.30 |
---|---|
print start recursive c example (0) | 2015.06.19 |
zigzag c exmaple (0) | 2015.06.19 |
fraction sort c example (0) | 2015.06.19 |
shortest path c example (0) | 2015.06.19 |
generate all combination of elements using 2-dimension vector (0) | 2015.04.30 |
RECENT COMMENT