满意答案
#include
#include
int main()
{
int **a, m, n, i, j, k, l;
printf("please input m & n:");
scanf("%d%d", &m, &n);
printf("please input the square:\n");
a = (int**)malloc(sizeof(int*) * m);
for(i = 0; i < m; ++i) {
a[i] = (int*)malloc(sizeof(int) * n);
for(j = 0; j < n; ++j) {
scanf("%d", &k);
l = j-1;
while(l >= 0 && a[i][l] > k) {
a[i][l+1] = a[i][l];
--l;
}
a[i][l+1] = k;
}
}
printf("\nafter sort:\n");
for(i = 0; i < m; ++i) {
for(j = 0; j < n; ++j)
printf("%d ", a[i][j]);
putchar('\n');
free(a[i]);
}
free(a);
return 0;
}
00分享举报