Comparing Numbers – HackerRank Solution

In this post, we will solve Comparing Numbers HackerRank Solution. This problem (Comparing Numbers) is a part of Linux Shell series.

Task

Given two integers, X and Y, identify whether X < Y or X > Y or X = Y.

Exactly one of the following lines:
– X is less than Y
– X is greater than Y
– X is equal to Y

Input Format

Two lines containing one integer each (X and Y, respectively).

Constraints

Output Format

Exactly one of the following lines:
– X is less than Y
– X is greater than Y
– X is equal to Y

Sample Input

Sample Input 1

5  
2  

Sample Input 2

2
2  

Sample Input 3

2
3  

Sample Output

Sample Output 1

X is greater than Y  

Sample Output 2

X is equal to Y   

Sample Output 3

X is less than Y  

Solution – Comparing Numbers – HackerRank Solution

#!/bin/bash
read X
read Y
if (( $X > $Y ))
then
    echo "X is greater than Y"
fi

if (( $X == $Y))
then
    echo "X is equal to Y"
fi

if(( $X < $Y))
then
    echo "X is less than Y"
fi

Note: This problem (Comparing Numbers) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *