日期:2014-05-18  浏览次数:20529 次

一个关于返回表格类型的面试题,高手可以进来看看~~
笔试中遇到一道题目如下(c#实现)
随便输入一个数N,   写一个函数返回以下结果

N*N   (N-1)*N   (N-2)*N     N
(N-1)*N   (N-2)*N   (N-3)*N   ……   N-1

(N-2)*N   (N-3)*N     (N-4)*N……   N-2

……   ……   ……   ……

N   N-1     N-2     ……   1


------解决方案--------------------
是否比如输入5...输出应该是
25 20 15 10 5
20 15 10 5 4
15 10 5 4 3
10 5 4 3 2
5 4 3 2 1
这样的效果
------解决方案--------------------
void print(int n){
for (int i=n;i> 0;i--){
int k = n;
for (int j=0;j <5;j++){
printf( "%d ",(i> j)?n*(i-j):--k);
}
putchar( '\n ');
}
}
------解决方案--------------------
Response.Write( " <table cellspacing= '0 ' cellpadding= '0 ' border=1> <tr> ");
int n = 0;n=10;
for(int i=n;i> 0;i--)
{
Response.Write( " <td> ");
for(int j=n; j> 0;j--)
{
int m = i*j;
Response.Write(m);
Response.Write( " </td> <td> ");
}
for(int d=0; d <=(n+1)*(n+1);d++)
{
if( d == i*n )
{
Response.Write( " </td> </tr> ");
}
}
}
Response.Write( " <table> ");
///////////////////////////////////


100 90 80 70 60 50 40 30 20 10
90 81 72 63 54 45 36 27 18 9
80 72 64 56 48 40 32 24 16 8
70 63 56 49 42 35 28 21 14 7
60 54 48 42 36 30 24 18 12 6
50 45 40 35 30 25 20 15 10 5
40 36 32 28 24 20 16 12 8 4
30 27 24 21 18 15 12 9 6 3
20 18 16 14 12 10 8 6 4 2
10 9 8 7 6 5 4 3 2 1