Answer to Question #84012 in C++ for abuky

Question #84012
receive 3 numbers and display them ascending order from the smallest to largest
1
Expert's answer
2019-01-04T04:43:11-0500

#include <iostream>

using namespace std;


int main()

{

const int N = 3;

int arr[N];

int min, mid, max;


cout << "Enter a first integer number: ";

cin >> arr[0];

cout << "Enter a second integer number: ";

cin >> arr[1];

cout << "Enter a third integer number: ";

cin >> arr[2];


// sort the numbers

min = mid = max = arr[0];

for (int i = 0; i < N; ++i)

{

int tmpMin = arr[i];

for (int j = i+1; j < N; ++j)

{

if(arr[j] < tmpMin)

{

tmpMin = arr[j];

arr[j] = arr[i];

arr[i] = tmpMin;

}

}

}


cout << endl << "Ascending order from the smallest to largest: " << arr[0] << " \t "<< arr[1] << " \t "<< arr[2] << endl;

return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS