Sort Three Integers

less than 1 minute read

The code has been modified slightly and now uploaded to the site.

Question

<— Return Home

37.cpp

#include <iostream>
#include <vector>
using namespace std;

int main(){
    double first;
    double second;
    double third;

    std::cout << "Enter three integers: \n";
    std::cin >> first;
    std::cin >> second;
    std::cin >> third;

    vector<int> array;
    array.push_back(first);
    array.push_back(second);
    array.push_back(third);

    int temp;
    for (int i = 0; i < 3; i++){
        for (int j = i + 1; j < 3; j++){
            if (array[i] > array[j]){
                temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
        }
    }
    std::cout << "\n";
    for (int i = 0; i < 3; i++){
        std::cout << array[i] << "\n";
    }
}

<— Return Home