2

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
831 B
2
Indexable
Never
#include <stdio.h>

int arr[11];

void sortfunc(first) {
    int min = 100;
    int min_pos = 11;

    if (first == 9) {
        printf("\nSorted array:\n");
        for (int i = 0; i < 10; i++) {
            printf("%d ", arr[i]);
        }
        printf("\n");

        return;
    }
    else {
        for (int i = first; i < 10; i++) {
            if (arr[i] < min) {
                min = arr[i];
                min_pos = i;
            }
        }

        if (min != arr[first]) {
            arr[min_pos] = arr[first];
            arr[first] = min;

        }

        sortfunc(first+1);
    }
}

int main() {


    printf("An array of 10 random integers in 10-99:\n");
    for (int i = 0; i < 10; i++) {
        scanf("%d", &arr[i]);
    }

    sortfunc(0);

    return 0;
}