Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <conio.h>
- #define MAX 50
- int i, j, a[MAX];
- char b;
- void createArray(int *a) {
- srand(time(NULL));
- for (i = 0; i < MAX; i++)
- a[i] = rand() % 100;
- }
- void printArray(int a[]) {
- for (i = 0; i < MAX; i++)
- printf("%i ", a[i]);
- printf("\n");
- }
- void selection_sort(int *a) {
- for (i = 0; i < MAX; i++) {
- int lower_index = i;
- int lower_number = a[i];
- for (j = i + 1; j < MAX; j++) {
- if (a[j] < lower_number) {
- lower_index = j;
- lower_number = a[j];
- }
- }
- int x = a[i];
- a[i] = a[lower_index];
- a[lower_index] = x;
- }
- }
- int main()
- {
- do {
- createArray(a);
- printf("Random array: ");
- printArray(a);
- selection_sort(a);
- printf("Sorted array: ");
- printArray(a);
- b = getch();
- printf("\n");
- } while (b != 27);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement