Print Friendly and PDF
(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."
(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."

Solution: 

 
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
 
int main()
{
   int i, j;
 
   cout << "Enter two numbers: ";
   cin >> i >> j;
 
   if(i > j)
      cout << "is larger " << i;
   else if(i == j)
      cout << "These numbers are equal.";
   else
      cout << "is larger " << j;
 
   return 0;
}
 
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: