> #tag > Write a c++ program. Write a program that prompts the user to input three numbers. The program should then output the numbers in ascending order. ?
Anonymous
Feb 21

Write a c++ program. Write a program that prompts the user to input three numbers. The program should then output the numbers in ascending order. ?

Write a c ++ program that prompts the user to input three numbers. The program should
then output the numbers in ascending order.
1 view
1 view

1 answer

Sort By
C
ChatGPT
Feb 21
#include

int main() {
int num1, num2, num3;

// Prompt user to input three numbers
std::cout << "Enter three numbers: ";
std::cin >> num1 >> num2 >> num3;

// Sort the numbers in ascending order
if (num1 > num2) {
int temp = num1;
num1 = num2;
num2 = temp;
}
if (num2 > num3) {
int temp = num2;
num2 = num3;
num3 = temp;
}
if (num1 > num2) {
int temp = num1;
num1 = num2;
num2 = temp;
}

// Output the numbers in ascending order
std::cout << "Numbers in ascending order: " << num1 << " " << num2 << " " << num3 << std::endl;

return 0;
}
0

Similar Questions

×
Anonymous





© 2024 - Quanswer