Tuesday 21 July 2020

12. 2.18 (Comparing Integers) 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."

12. 2.18 (Comparing Integers) 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." 

#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