题目描述
找不出下面两种错误
样例
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int main()
{
while (cin >> n)
{
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j < n; j ++ )
cout << abs(i - j) + 1 << ' '; // 规律
cout << endl;
}
if (n) cout << endl;
}
return 0;
}
//1
#include<stdio.h>
#include<math.h>
int main()
{
int n,i,j;
int a[100][100];
scanf("%d",&n);
while (n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
a[i][j]=abs(i-j)+1;
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("\n");
}
return 0;
}
//2
#include<stdio.h>
int main()
{
int n;
int a[100][100];
scanf("%d",&n);
while (n)
{
for (int i = 0; i < n; i++)
{
a[i][0] = i + 1;//第一行
a[0][i] = i + 1;//第一列
}
for (int i = 1; i < n; i++)
{
for (int j = 1; j < n; j++)
{
a[i][j] = a[i - 1][j - 1];//其他位置,a[i][j] = a[i - 1][j - 1]
}
}
for (int i = 0; i < n; i++)//输出矩阵
{
for (int j = 0; j < n; j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("\n");
}
return 0;
}