-
Notifications
You must be signed in to change notification settings - Fork 16
/
9.c
46 lines (41 loc) · 1.08 KB
/
9.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>
void swap_two_elements_from_an_array(int array[], int first_element_index, int second_element_index)
{
int temp = array[first_element_index];
array[first_element_index] = array[second_element_index];
array[second_element_index] = temp;
}
int main()
{
int element_number_of_array;
printf("Enter element number of array: ");
scanf("%d", &element_number_of_array);
int array[element_number_of_array];
int i, j;
for (i=0; i<element_number_of_array; i++)
{
printf("Enter element %d of array: ", i+1);
scanf("%d", &array[i]);
}
int minimum;
for(i=0; i<element_number_of_array; i++)
{
minimum = i;
for(j=i+1; j<element_number_of_array; j++)
{
if (array[j] < array[minimum])
{
minimum = j;
}
}
if (minimum != i)
{
swap_two_elements_from_an_array(array, i, minimum);
}
}
printf("Sorted array: ");
for (i=0; i<element_number_of_array; i++)
{
printf("%d ", array[i]);
}
}