Translate

Write a program that asks the user to enter two integers


Q:
Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words "is larger." If the numbers are equal, print the message “These numbers are equal.”

Answer:


#include <iostream>
using namespace std;
int main()
 {
 int num1, num2; // declaration

 cout << "Enter two integers: "; // prompt
 cin >> num1 >> num2; // input to numbers

 if ( num1 == num2 )
 cout << "These numbers are equal." << endl;

 if ( num1 > num2 )
 cout << num1 << " is larger." << endl;

  if ( num2 > num1 )
 cout << num2 << " is larger." << endl;

 return 0;
  }

No comments:

Post a Comment