/*
Example: sort array in ascending order using C language
*/
#include <stdio.h>
#include <stdlib.h>
void printArr(int* arr,int len){
for (int i = 0; i < len; ++i){
printf("%d ",arr[i]);
}
printf("\n");
}
int main(int argc, char const *argv[]) {
int num[] = { 1,6,7,9,3,5,4,2,17,12};
int len = sizeof(num)/sizeof(num[0]);
int temp;
printArr(num,len);
for (int i = 0; i < len; ++i){
for (int j = i + 1; j < len; ++j){
if (num[i] > num[j]){
temp = num[i];
num[i] = num[j];
num[j] = temp;
}
}
}
printArr(num,len);
return 0;
}Scruoe:www.lautturi.comexample of output:
1 6 7 9 3 5 4 2 17 12 1 2 3 4 5 6 7 9 12 17 Process returned 0 (0x0) execution time : 0.108 s Press any key to continue.