关于一维数组与二维数组的输入输出问题
写了一个排序的代码但我发现了一个问题
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
int maxn[100];
int n;
int c=0;
int a[100];
scanf("%d", &n);
for(int i=1;i<=n;i++){
scanf("%d", &a[i]);
}
for(int i=1;i<=n;i++){
maxn[i]=i;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n-1;j++){
if(a[maxn[j]]<a[maxn[j+1]]){
c=maxn[j];
maxn[j]=maxn[j+1];
maxn[j+1]=c;
}
for(int q=1;q<=n;q++){
cout<<a[maxn[q]]<<' ';
}
cout<<endl;
}
}
return 0;
}
上面的代码能正常输出但把啊a[x]换成a[1][x]后就输出不了
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
int maxn[100];
int n;
int c=0;
int a[1][100];
scanf("%d", &n);
for(int i=1;i<=n;i++){
scanf("%d", &a[1][i]);
}
for(int i=1;i<=n;i++){
maxn[i]=i;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n-1;j++){
if(a[1][maxn[j]]<a[1][maxn[j+1]]){
c=maxn[j];
maxn[j]=maxn[j+1];
maxn[j+1]=c;
}
for(int q=1;q<=n;q++){
cout<<a[1][maxn[q]]<<' ';
}
cout<<endl;
}
}
return 0;
}