C++ program to find the Greatest of the Two Numbers 

Find the Greatest of the two numbers in C++

Given two integer inputs num1 and num2, the objective if to write a code to Find the Greatest of the     

Two Numbers in C++.

Example

Input : num1 = 5 and num2 = 6

Output : 6

Flow Diagram:-

Greatest of two numbers.png

Code:-

  • If num1 == num2

  •        Print both are equal

  • Else if num1 > num2

  •       Print num1 is greater

  • Else, num2 has to be the greater

  •       Print num2 is greater

Algorithm:-

Code:-

#include<iostream>
using namespace std;

int main ()
{
    int num1, num2;
    cout << "Insert two numbers: " << endl; 
    cin >> num1 >> num2;
 
    if (num1 == num2)
        cout << "both are equal"; 
    else if (num1 > num2)
        cout << num1 << " is greater than " << num2;
    else
        cout << num2 << " is greater than " << num1;

    return 0;
}

Output:-

Enter a number: 22 10

22 is greater