Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Comparing Numbers problem solution

YASH PAL, 31 July 2024

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 linux shell

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
©2025 Programming101 | WordPress Theme by SuperbThemes