Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Ordered output of three integers
- //
- // User inputs 3 integers
- // The program output these integers ordered
- #include "std_lib_facilities.h"
- int main()
- {
- // promt user to input numbers
- cout << "Enter three integers:\n";
- int init_value{0};
- // user input vars
- int input1{init_value};
- int input2{init_value};
- int input3{init_value};
- cin >> input1 >> input2 >> input3;
- // vars for output
- int output1{init_value};
- int output2{init_value};
- int output3{init_value};
- // when 1st will be printed before 2nd - 3 solutions possible:
- //
- // (1st 2nd 3rd)
- // (1st 3rd 2nd)
- // (3rd 1st 2nd)
- //
- if (input1 <= input2) {
- if (input2 <= input3){
- output1 = input1;
- output2 = input2;
- output3 = input3;
- }
- if (input2 > input3 ){
- if (input1 <= input3) {
- output1 = input1;
- output2 = input3;
- output3 = input2;
- }
- if (input1 > input3){
- output1 = input3;
- output2 = input1;
- output3 = input2;
- }
- }
- }
- // when 2nd will be printed before 1st - 3 solutions possible:
- //
- // (2nd 1st 3rd)
- // (3rd 2nd 1st)
- // (2nd 3rd 1st)
- if (input1 > input2) {
- if (input2 > input3){
- output1 = input3;
- output2 = input2;
- output3 = input1;
- }
- if (input2 <= input3 ){
- if (input1 <= input3) {
- output1 = input2;
- output2 = input1;
- output3 = input3;
- }
- if (input1 > input3){
- output1 = input2;
- output2 = input3;
- output3 = input1;
- }
- }
- }
- // output ordered values
- cout << output1 << ' ' << output2 << ' ' << output3;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement