This is my code: //buble sort
#include<stdio.h>
int main(){
int a[11];
int temp;
int i,j;
//input
for(i=1;i<=10;i++){
scanf("%d",&a[i]);
}
//sort
for(i=1;i<10;i++){ //the number of number
for(j=1;j<10-i;j++) //--
if(a[j]<a[j+i]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
//output
for(i=1;i<=10;i++){
printf("%d ",a[i]);
}
getchar();
getchar();
return 0;
}
but the result was not like what I think.the number before was 1 2 3 4 5 6 7 8 9 0 but after it was 8 6 5 4 3 7 2 9 1 0 thanks !
Aucun commentaire:
Enregistrer un commentaire