Three numbers denoted by the variables A, B and C are supplied as input data. Print these three numbers in ascending order.
#include <iostream>
int main()
{
int A, B, C;
int v1, v2, v3;
std::cout << "Please enter a variable A";
std::cin >> A;
std::cout << "Please enter a variable B";
std::cin >> B;
std::cout << "Please enter a variable C";
std::cin >> C;
if (A >= B)
{
if (A >= C)
{
v3 = A;
if (C >= B)
{
v1 = B;
v2 = C;
}
else
{
v1 = C;
v2 = B;
}
}
else
{
v1 = B;
v2 = A;
v3 = C;
}
}
else
{
if (B < C)
{
v1 = A;
v2 = B;
v3 = C;
}
else
{
v3 = B;
if (C >= A)
{
v1 = A;
v2 = C;
}
else
{
v1 = C;
v2 = A;
}
}
}
std::cout << v1 << " " << v2 << " " << v3 << std::endl;
}
Comments
Leave a comment