C語言-18.有一個數組,int a[10] = {2,8,6,3,4,7,9,12,1,0},請將陣列內元素排序

2020-08-09 13:52:49

 

#include <stdio.h>

 

#include <stdlib.h>

 

int main(int* argc, char* argv[])

 

{

 

int a[10] = { 2,8,6,3,4,7,9,12,1,0 };

 

for (int i = 0; i < 10; i++)

 

{

 

for (int j = i + 1; j < 10; j++)

 

{

 

if (a[i] > a[j])

 

{

 

int temp = a[i];

 

a[i] = a[j];

 

a[j] = temp;

 

}

 

}

 

}

 

for (int i = 0; i < 10; i++)

 

{

 

printf("%d\n",a[i]);

 

}

 

return 0;

 

}