How to write a C Program Sort in C Programming Language ?
Solution For C Program :
/*C Program Sort.*/
#include <stdio.h>
int main(){
int a[5] = {5, 4, 2, 3, 1};
// Sort: Sequence
// A position lined up
int i;
for( i = 0 ; i < 5 ; i++ ){
// Find the smallest number
int min = i; // I suppose the first individual minimum
int j;
for( j = i+1 ; j < 5 ; j++ ){
if( a[j] < a[min] ){
min = j;
}
}
// Exchange smallest number with me to wait (item i) of digital
/*
Swap: Exchange
int temp = a;
a = b;
b = temp;
*/
int temp = a[i];
a[i] = a[min];
a[min] = temp;
}
// Export
for( i = 0 ; i < 5 ; i++ ){
printf("%d\n", a[i]);
}
return 0;
}