+ 3
How can I sort three numbers in decreasing order?
The user is gonna give me values to three variables: A, B C. But there's a problem... I want A to be the largest number, B the second largest and C the smallest. But what if the user types 3 4 5 or 4 5 3 instead of 5 4 3? I want the program to reorganize the numbers in decreasing order, so if the user types 3 4 5, the program will make A be 5, 4 be B and 3 be C, regardless of the original order. I want the solution using c++. Please, help me :)
8 Answers
+ 2
You can write some simple statements to check the values and rearrange before you move into the core part of your program.
ex:
if(A<B)
{
int temp = A;
A = B;
B = temp;
}
if(A<C)
{
temp = A;
A = C;
C = temp;
}
if(B<C)
{
temp = B;
B = C;
C = temp;
}
+ 3
Thank you
+ 1
its just a temporary integer variable to store the original value of A (or B) so you can get your values reassigned in the order you want them in. you can call it whatever you want. temp, t, heythere
+ 1
Thank you đ
0
https://code.sololearn.com/cTEuTsIl4Vgg/?ref=app
Here's my code. What should I write?
0
Hi, Elizabeth. What's temp?
- 2
look at your object spefulyiers and find the objected type