J
John
Hi all,
I wrote the code to get the following output:
1 2 3 4 5 6 7 8 9 10
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7 8 9 10
2 1 3 4 5 6 7 8 9 10
1 3 2 4 5 6 7 8 9 10
3 2 4 1 5 6 7 8 9 10
2 4 1 5 3 6 7 8 9 10
4 1 5 3 6 2 7 8 9 10
1 5 3 6 2 7 4 8 9 10
5 3 6 2 7 4 8 1 9 10
3 6 2 7 4 8 1 9 5 10
6 2 7 4 8 1 9 5 10 3
but,the output received from the code is different.
there is some mistake and I got confusion on.if you
know some better advice and correction to my code,
please show it.
tanx a lot!
the code wrote by me is as below:
#include<stdio.h>
int main(){
int a[10][10];
int i,j,k,temp;
printf("input the integer\n");
for(i=0;i<10;i++)
scanf("%d",&a[0]);
printf("put the integer 9times\n");
for(i=0;i<9;i++){
scanf("%d",&temp);
a[i+1][temp-1] = a[0];
for(j=0;j<temp-1;j++)
a[i+1][j] = a[j+1];
for(j=temp;j<10;j++)
a[i+1][j] = a[j];
}
for(i=0;i<10;i++){
for(j=0;j<10;j++){
printf("%d ",a[j]);
}
printf("\n");
return 0;
}
}
I wrote the code to get the following output:
1 2 3 4 5 6 7 8 9 10
2
3
4
5
6
7
8
9
10
1 2 3 4 5 6 7 8 9 10
2 1 3 4 5 6 7 8 9 10
1 3 2 4 5 6 7 8 9 10
3 2 4 1 5 6 7 8 9 10
2 4 1 5 3 6 7 8 9 10
4 1 5 3 6 2 7 8 9 10
1 5 3 6 2 7 4 8 9 10
5 3 6 2 7 4 8 1 9 10
3 6 2 7 4 8 1 9 5 10
6 2 7 4 8 1 9 5 10 3
but,the output received from the code is different.
there is some mistake and I got confusion on.if you
know some better advice and correction to my code,
please show it.
tanx a lot!
the code wrote by me is as below:
#include<stdio.h>
int main(){
int a[10][10];
int i,j,k,temp;
printf("input the integer\n");
for(i=0;i<10;i++)
scanf("%d",&a[0]);
printf("put the integer 9times\n");
for(i=0;i<9;i++){
scanf("%d",&temp);
a[i+1][temp-1] = a[0];
for(j=0;j<temp-1;j++)
a[i+1][j] = a[j+1];
for(j=temp;j<10;j++)
a[i+1][j] = a[j];
}
for(i=0;i<10;i++){
for(j=0;j<10;j++){
printf("%d ",a[j]);
}
printf("\n");
return 0;
}
}