Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Operating Systems

Lab Assignment – 5

Implementation of If – Else Loops

Aayushi Verma
18070124003
Batch – T1
1) Even and Odd Numbers:
Code:
echo "******************Even or Odd*******************"
echo "Enter a number: "
read num
if [ $((num % 2)) -eq 0 ]
then
echo "The number entered is even."
else
echo "The number entered is odd."
fi
echo "****************************************************"
Output:

2) Greatest of 3 numbers:
Code:
echo "**************Greatest out of 3 numbers*********************"
echo "Enter the first number: "
read num1
echo "Enter the 2nd number: "
read num2
echo "Enter the 3rd number: "
read num3
if [ $num1 -gt $num2 ] && [ $num1 -gt $num3 ]
then
echo "$num1 is the greatest of the 3 numbers."
elif [ $num2 -gt $num1 ] && if [ $num2 -gt $num3 ]
then
echo "$num2 is the greatest of the 3 numbers."

else
echo "$num3 is the greatest of the 3 numbers."
fi
echo “*****************************************************"
Output:
3) To check if the year is a Leap Year or Not:
Code:
echo "******************Leap Year or not*******************"
echo "Enter the year: "
read year
if [ $((year % 4)) -eq 0 ]
then
if [ $((year % 100)) -eq 0 ]
then
if [ $((year % 400)) -eq 0 ]
then
echo "$year is a leap year"
else
echo "$year is not a leap year"
fi
else
echo "$year is a leap year"
fi
else
echo "$year is not a leap year"
fi

echo "***********************************************"
Output:
4) Tax Calculation:
Code:
echo "********************Tax Calculation********************"
echo "Enter Account Balance: "
read acc_bal
echo "Enter the amount to withdraw: "
read withdraw
if [ $acc_bal -lt $withdraw ]
then
echo "Since the withdrawl amount is Greater than the Account Balance"
echo "Therefore, Insufficient Balance"

else
if [ $withdraw -lt 1500 ]
then
echo "Since the withdrawl amount is Less than 1500"
tax=`expr $withdraw \* 3 / 100|bc`
bal=`expr $acc_bal - $withdraw`
echo "Tax: $tax"
elif [ $withdraw -gt 3000 ]
then
echo "Since the withdrawl amount is Greater than 3000"
tax=`expr $withdraw \* 5 / 100|bc`
bal=`expr $acc_bal - $withdraw`
echo "Tax: $tax"

elif [ $withdraw -gt 1500 ] && [ $withdraw -lt 3000 ]


then
echo "Since the withdrawl amount is Between 1500 and 3000"
tax=`expr $withdraw \* 4 / 100|bc`
bal=`expr $acc_bal - $withdraw`
echo "Tax: $tax"

fi

fi
echo "Withdrawn amount: $withdraw"
echo "Current Account Balance: $bal"
echo "********************************************************"

Output:
​***Fin.***

You might also like