|
|
楼主 |
发表于 2013-6-15 23:30:52
|
显示全部楼层
参考答案:
/**************************************************************
* Copyright (C) 2006-2013 All rights reserved.
* @Version: 1.0
* @Created: 2013-05-01 21:09
* @Author: guozi - qin@126.com
* @Description:
*
* @History:
**************************************************************/
#include <stdio.h>
#define MAX_COL 2*100 - 1 //max column
#define MAX_ROW MAX_COL
/**
* @brief output
*
* @Param: N
*/
void output(int N)
{
int a[MAX_COL][MAX_ROW] = {0};
int col,row,i;
if( 2*N - 1 > MAX_COL )
{
printf(" lease input a number between[1-199]\n");
return ;
}
/*Initialize array a*/
for(i=0; i<N; i++)
{
for(col = i,row = i; col < 2*N - 1 - i; col++)
a[row][col] = i + 1;
for(row= i,col = i; row < 2*N - 1 - i; row++)
a[row][col] = i + 1;
for(col=i,row=2*N-2-i; col < 2*N - 1 - i; col++)
a[row][col] = i+1;
for(row=i,col=2*N-2-i; row < 2*N - 1 - i; row++)
a[row][col] = i+1;
}
/*output array*/
for(row=0; row<2*N-1;row++)
{
for(col=0; col<2*N-1;col++)
printf("%2d ",a[row][col]);
printf("\n");
}
}
int main()
{
int N;
printf(" lease input a number:");
scanf("%d",&N);
output(N);
return 0;
} |
|