- 论坛徽章:
- 0
|
有关c语言的两道题~~~很简单的~
分配内存我就不说了,现我把第二题的写出来;
int toprow,bottomrow,leftcol,rightcol;
int i,j,n;
int **a;
.
.
.
j = 1;
toprow = 0;
bottomrow = n;
leftcol = 0;
rightcol = n;
while((bottomrow>;toprow)&&(rightcol>;leftcol))
{
for(i=leftcol;i<rightcol;i++)
{
a[toprow] = j;
j++;
}
toprow ++;
for(i=toprow;i<bottomrow;i++)
{
a[rightcol-1] = j;
j++;
}
rightcol --;
for(i=rightcol-1;i>;=leftcol;i--)
{
a[bottomrow-1] = j;
j ++;
}
bottomrow --;
for(i=bottomrow-1;i>;=toprow;i--)
{
a[leftcol] = j;
j ++;
}
leftcol ++
}
.
.
. |
|