-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber Sorter
More file actions
39 lines (31 loc) · 864 Bytes
/
Number Sorter
File metadata and controls
39 lines (31 loc) · 864 Bytes
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
#include <iostream>
#include <vector>
int main ()
{
std::vector<double> num_list;
double input;
int amount;
std::cout << "Berapa angka yang ingin anda urutkan? ";
std::cin >> amount;
std::cout << "Masukkan angka-angka yang ingin diurutkan\n";
for (int z = 1; z <= amount; z++) {
std::cin >> input;
num_list.push_back(input);
}
int size = num_list.size();
double temp;
for (int m = 1; m < size; m++) {
for (int i = 0; i < size-1; i++) {
if (num_list[i] > num_list[i+1]) {
temp = num_list[i];
num_list[i] = num_list[i+1];
num_list[i+1] = temp;
}
}
}
std::cout << "Urutan angka dari yang terkecil ke yang terbesar adalah:\n";
for (int m = 0; m < size; m++) {
std::cout << num_list[m] << " ";
}
return 0;
}