Answer to Question #345279 in C++ for Ali

Question #345279

Three numbers denoted by the variables A, B and C are supplied as input data. Print these three numbers in ascending order.


1
Expert's answer
2022-05-30T08:15:10-0400
#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;
}

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