Homework record-Simple sorting

我要成为(c语言)高手發表於2024-04-06

include <stdio.h>

int main(int argc, const char * argv[]){
int n,m,j,i,t;
printf("please enter the number of numbers:");
scanf("%d",&n);
int a[n];
for (i=0; i<n; i++) {
scanf("%d",&a[i]);
for (j=0; j<i; j++) {
if (a[j]>a[i]) {
t=a[i];
for (m=0; m<=i-j-1; m++) {
a[i-m]=a[i-m-1];
}
a[j]=t;
}
}
}
for (i=0; i<n; i++)
printf("%d",a[i]);
return 0;
}

相關文章