Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- const int ARR_SIZE = 5;
- int main(int argc, char* argv[]) {
- int arr[ARR_SIZE];
- std::cout << "Enter " << ARR_SIZE << " numbers: " << std::endl;
- int summ = 0;
- for (int i = 0; i < ARR_SIZE; ++i) {
- std::cin >> arr[i];
- summ += arr[i];
- }
- for (int i = 0; i < ARR_SIZE; ++i) {
- bool is_sorted = true;
- for (int j = 0; j < ARR_SIZE-i-1; ++j) {
- if (arr[j] > arr[j+1]) {
- is_sorted = false;
- int tmp = arr[j+1];
- arr[j+1] = arr[j];
- arr[j] = tmp;
- }
- }
- if (is_sorted) break;
- }
- std::cout << "Your sorted array: \n";
- for (int i = 0; i < ARR_SIZE; ++i) {
- std::cout << arr[i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement