Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerRank Comparing Numbers problem solution

YASH PAL, 31 July 20246 February 2026

In this HackerRank Comparing Numbers problem solution Comparisons in a shell script may either be accomplished using regular operators (such as <, > or =) or using the equivalent (-lt, -gt, -eq) for POSIX shells.

if statements take the form

if [[ condition ]]

then

    do this

elif [[ condition ]]

then

    do this instead

else

    do this by default

fi

Note the spacing on the conditionals. There must be a space between the brackets and their contents, e.g.

if [[ $a < $b ]]

we have 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

HackerRank Comparing Numbers problem solution

Problem solution.

#!/bin/bash

read x
read y

if [ $x -lt $y ]; then
    echo "X is less than Y"
elif [ $x -gt $y ]; then
    echo "X is greater than Y"
else
    echo "X is equal to Y"
fi

Second solution.

#!/bin/bash

read x
read y

if [ $x -lt $y ]; then
    echo "X is less than Y"
elif [ $x -eq $y ]; then
    echo "X is equal to Y"
else
    echo "X is greater than Y"
fi

coding problems solutions Hackerrank Problems Solutions linux shell HackerRankLinux shell

Post navigation

Previous post
Next post

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes