You are on page 1of 9

LAB 4

ASAD IKRAM
17K3943
A

PROBLEM 1

Addition()

echo "Enter 2 numbers to add"


read num1 num2
result=$((num1+num2))
echo "Answer is: $result"
}
Addition

PROBLEM 2

LargestNum()
{
echo "Enter 3 numbers to find the largest"
read num1 num2 num3

if [ "$num1" -gt "$num2" ] && [ "$num1" -gt "$num3" ];


then
echo "$num1 is Larger than $num2 and $num3"

elif [ "$num2" -gt "$num1" ] && [ "$num2" -gt "$num3" ];

then
echo "$num2 is Larger than $num1 and $num3"

elif [ "$num3" -gt "$num1" ] && [ "$num3" -gt "$num2" ];

then
echo "$num3 is Larger than $num1 and $num2"

else
echo "same"
fi
}

LargestNum
PROBLEM 5

Detail()
{
echo "Current Date:"

date

echo "Username:"
whoami

echo "Current direcotry:"

pwd

}
Detail

PROBLEM 3
#!/bin/bash
echo "1 for + "
echo "2 for - "
echo "3 for * "
echo "4 for / "

echo "Enter first number: "


read num1
echo "Enter second number: "
read num2

echo "Choose Mathematical Operation: "


read $input

case $input in
pattern-1)

Result=$(( num1+num2 ))
echo $Result
;;

pattern-2)
echo Result=$(( num1-num2 ))
;;
*)

echo "unknown"
;;
Esac
PROBLEM 4

#!/bin/bash
echo "Enter first number: "
read num1

sum=0
while [ $num1 -gt 0 ]
do
a=$(( $num1 % 10 ))
num1=$(( $num1 / 10 ))
sum=$(( $sum + $a ))
done
echo "SUM IS: $sum"

You might also like