Skip to main content

Posts

Showing posts with the label Write a program to read two numbers from the keyboard and display the larger value on the screen.

Write a program to read two numbers from the keyboard and display the larger value on the screen.

 Here's the program to read two numbers from the keyboard and display the larger value on the screen: c++ Copy code #include <iostream> using namespace std; int main() {    int num1, num2;    cout << "Enter first number: ";    cin >> num1;    cout << "Enter second number: ";    cin >> num2;    if (num1 > num2) {       cout << "Larger number is: " << num1 << endl;    }    else {       cout << "Larger number is: " << num2 << endl;    }    return 0; } Sample output: Enter first number: 23  Enter second number: 45 Larger number is: 45 Explanation: The program starts by including the necessary header file iostream which contains the standard input/output library in C++. using namespace std; statement is used to avoid typing std:: before standard library objects. Two integer variab...