Shell script to find greatest of three numbers
In this chapter of shell script programs, we will learn:
-
find greatest of 3 numbers in shell script
Shell script to find greatest of three numbers
In this example, we will find greatest of 3 numbers in shell script. To solve this problem, we have to know few topics-
-
‘echo’ statement
-
‘read’ command
-
‘if-else’ statement
-
How to check condition in shell script
-
'gt', 'ge' commands
ALGORITHM:
Below algorithm shows steps of how to find greatest of three numbers in linux:
-
STEP 1: START THE PROBLEM
-
STEP 2: TAKE THREE INPUTS FROM THE USER
-
STEP 3: IN IF-ELSE CONDITION, CHECK WHICH IS THE GREATEST
-
STEP 4: ALSO CHECK WITH THE THIRD NUMBER
-
STEP 5: FIND THE RESULT
-
STEP 6: PRNT THE RESULT
-
STEP 7: STOP THE PROGRAM
CODE:
Shell script to find the largest of three numbers using command line arguments:
clear
echo "---FIND THE GREATEST AMONG THREE NUMBERS---"
echo "Enter 1st number:"
read first_num
echo "Enter 2nd number:"
read second_num
echo "Enter 3rd number:"
read third_num
if test $first_num -gt $second_num && test $first_num -gt $third_num
then
echo $first_num is the greatest number.
elif test $second_num -gt $third_num
then
echo $second_num is the greaatest number.
else
echo $third_num is the greatest number.
fi
CODE IMAGE IN CYGWIN:
OUTPUT:
---FIND THE GREATEST AMONG THREE NUMBERS---
Enter 1st number:
45
Enter 2nd number:
343
Enter 3rd number:
23
343 is the greaatest number.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Page Views :
Published Date :
Feb 19,2021