English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

input three numbers and find out which one is smallest of them. like input a,b,c
and print if "a,b or c is the smallest.......... i tried but this not worked

echo "enter 3 numbers"
read a b c
if [ $a -lt $b ]
then
if [$a -lt $c ]
then
echo "a is the smallest"
fi

elif [ $b -lt $a ]
then
if [ $b -lt $c ]
then
echo "b is the smallest"

else
echo "c is the smallest"
fi
fi

2006-11-26 02:54:54 · 1 answers · asked by parwan005 1 in Computers & Internet Programming & Design

1 answers

You are almost there. This works:
#!/bin/sh
echo "enter 3 numbers"
read a b c
######################
if [ $a -lt $b ]
then
if [ $a -lt $c ]
then echo "a is smallest"
fi
fi
######################
if [ $b -lt $a ]
then
if [ $b -lt $c ]
then echo "b is smallest"
fi
fi
######################
if [ $c -lt $b ]
then
if [ $c -lt $a ]
then echo "c is smallest"
fi
fi

2006-11-26 03:35:11 · answer #1 · answered by DadOnline 6 · 0 0

fedest.com, questions and answers