6/recent/ticker-posts

Maximum of 3 : Bash Script

Write a  program to find the maximum of 3 numbers.

Note: #!/bin/sh  - include this command in first line

Input Format:

Input consists of 3 lines. Each line consists of an integer.

Output Format:

Output consists of a single line. Refer sample output for the format.

Sample Input :

3

5

1

 

Sample Output :

5 is the maximum number


Answer:

#!/bin/sh
read a
read b
read c
if [ $a -gt $b ] && [ $a -gt $c ]
then 
    echo "$a is the maximum number"
fi
if [ $c -gt $b ] && [ $c -gt $a ]
then 
    echo "$c is the maximum number"
fi
if [ $b -gt $a ] && [ $b -gt $c ]
then 
    echo "$b is the maximum number"
fi

Suggested Books:



Post a Comment

0 Comments