-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path06_sort.c
62 lines (52 loc) · 1.59 KB
/
06_sort.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// // Write a program to sort (ascending order) elements of an array of size 10. Take array values from the user.
// // Header Files
#include <stdio.h>
#include <conio.h>
#define ARRAY_SIZE 10
// // Main Function Start
int main()
{
int nums[ARRAY_SIZE];
printf("\nEnter 10 Numbers => ");
// // Input Numbers
for (int i = 0; i < ARRAY_SIZE; i++)
scanf("%d", &nums[i]);
// // Print Numbers
puts("\n>>>>>>>> Numbers Before Sorting <<<<<<<<<");
for (int i = 0; i < ARRAY_SIZE; i++)
printf("%d ", nums[i]);
// // Sorting using Selection Sort
// // for (int i = 0; i < ARRAY_SIZE - 1; i++)
// // {
// // for (int j = i + 1; j < ARRAY_SIZE; j++)
// // {
// // if (nums[i] > nums[j]) // // true, then swap
// // {
// // int temp = nums[i];
// // nums[i] = nums[j];
// // nums[j] = temp;
// // }
// // }
// // }
// // Sorting using Bubble Sort
// // for (int i = 0; i < ARRAY_SIZE - 1; i++)
// // {
// // for (int j = 0; j < ARRAY_SIZE - 1 - i; j++)
// // {
// // if (nums[j] > nums[j + 1]) // // true, then swap
// // {
// // int temp = nums[j];
// // nums[j] = nums[j + 1];
// // nums[j + 1] = temp;
// // }
// // }
// // }
// // Print Numbers
puts("\n\n>>>>>>>> Numbers After Sorting <<<<<<<<<");
for (int i = 0; i < ARRAY_SIZE; i++)
printf("%d ", nums[i]);
putch('\n');
getch();
return 0;
}
// // Main Function End