G8 of 3 Nos
G8 of 3 Nos
PROGRAM:
echo enter 3 numbers read a b c if [ $a -gt $b -a $a -gt $c ] then echo a is greatest elif [ $b -gt $c ] then echo b is greatest else echo c is greatest fi
OUTPUT:
[exam@fosslab shamu]$shamu.sh Enter 3 nos 269 C ia greatest
PROGRAM:
echo Enter the number read n i=1 f=1 while [ $i -lt $n ] do f=`expr $f \* $i` i=`expr $i + 1` done echo Factorial = $f
OUTPUT:
[exam@fosslab shamu]$sh fac.sh Enter the number 5 Factorial=24
PROGRAM:
x=1 sum=0 read n while [ $x -lt $n ] do sum=`expr $sum + $x` x=`expr $x + 2` done echo Sum is $sum
OUTPUT:
[exam@fosslab shamu]$sh sum.sh 4 Sum is 4
PROGRAM:
echo enter the Limit p=-1 q=1 read n I=1 while [ $I le $n ] do r= `expr $p + $q` echo $r p=`expr $q` q=`expr $r` I=`expr $I + 1` done
OUTPUT:
[exam@fosslab shamu]$sh fibo.sh Enter the limit 4 0 1 1 2
PROGRAM:
echo Enter 2 numbers read a b echo 1-ADD 2-SUB 3 MUL 4-MOD 5-EXIT read op case $op in 1)c=`expr $a + $b`;; 2)c=`expr $a - $b`;; 3)c=`expr $a \* $b`;; 4)c=`expr $a % $b`;; 5)exit esac echo $c
OUTPUT:
[exam@fosslab shamu]$sh cal.sh Enter 2 nos 5 6 1-add 11
PROGRAM:
echo Enter Farein temp read f a=`expr $f - 32` b=`expr $a \* 5` c=`expr $b / 9` echo $a $b $c
PROGRAM:
yy=0 isleap="false" echo -n "Enter year (yyyy) : " read yy if [ $((yy % 4)) -eq 0 ] ; then isleap=true elif [ $((yy % 400)) -eq 0 ] ; then isleap="true" elif [ $((yy % 100)) -eq 0 ] ; then isleap="false" fi if [ "$isleap" == "true" ]; then echo "$yy is leap year" else echo "$yy is NOT leap year" fi
OUTPUT:
[exam@cselab1 shamu]$sh leap.sh Enter year (yyyy):2012 2012 is leap year 1993 is not a laep year