Comparing Numbers HackerRank Solution

Hello coders, In this post, you will learn how to solve Comparing Numbers HackerRank Solution. This problem is a part of the Linux Shell series.

Comparing Numbers HackerRank Solution
Comparing Numbers HackerRank Solution

Problem

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

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  chase2learn. This tutorial is only for Learning and Educational purpose.

Sharing Is Caring