Shell Script to find greatest of Three numbers : SOLVED with ALGORITHM

Problem Statement

Write a shell script to find the largest number among three numbers

Algorithm

Step 1 : Start
Step 2 : Display “Enter 3 Numbers”
Step 3 : read a
Step 4 : read b
Step 5 : read c
Step 6 : if a>b and a>c
display a is the largest Number
Step 7 : else if b>a and b>c
Display b is the largest Number
Step 8 : else
Display c is the largest Number
Step 9 : Stop

Source Code

#! /bin/bash
# Author : Sounak Pal
#Website : cs.sounak.in
## Script to find the biggest number
echo "Enter 3 Numbers"
read a
read b
read c
if (($a>$b && $a>$c))
   then
      echo "$a is the largest Number"
   elif (($b>$a && $b>$c))
   then
      echo "$b is the largest Number"
   else
      echo "$c is the largest Number"
   fi

Input

Enter 3 Numbers
7418
8529
9514

Output

9514 is the largest Number

Leave a Comment

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