二维数组用for循环输出?
#include<stdio.h>
#include<math.h>
int main()
{
int n[4][5];
int input;
int diff;
int re;
n[0][0] = 11;
n[1][0] =21;
n[2][0] = 31;
n[3][0] = 41;
for(int i = 1; i < 5; i++)
{
n[0][i] = 11 + i;
n[1][i] =21 + i;
n[2][i] = 31 + i;
n[3][i] = 41 + i;
}
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 5; j++)
printf("%d ",n[i][j]);
printf("\n");
}
printf("Input a integer(q to quit): ");
while(scanf("%d",&input) == 1)
{
re = n[0][0];
diff = abs(n[0][0] - input);
for(int i = 0; i < 4; i++)
for(int j = 0; j < 5; j++)
{
if(diff > abs(n[i][j]-input))
{
diff = abs(n[i][j]-input);
re = n[i][j];
}
}
printf("The nearlly number is %d\n", re);
printf("Input a integer(q to quit): ");
}
return 0;
}