Sem 3‎ > ‎OS (Unix) LAB‎ > ‎

### Pz: All programs done In File.

posted Nov 15, 2011, 6:25 AM by Neil Mathew   [ updated Nov 15, 2011, 6:26 AM ]

## Q1. FIND SUM OF 5 NATURAL NUMBERS

echo "Enter 5 numbers: "
sum=` expr \$a + \$b + \$c + \$d + \$e `
echo "Sum of 5 numbers = \$sum"

## Q2. FIND THE AREA OF CIRCLE

echo "Enter the radius of the Circle: "
area=` expr 22 / 7 \* \$r \* \$r`
echo "Ans is \$area"

## Q3. CALCULATE THE SIMPLE INTEREST

echo "Enter the Principal: "
echo "Enter the Rate per year: "
echo "Enter the Time in years: "
SI=`expr \$P \* \$R \* \$T / 100`
echo "The Simple Interest is " \$SI

## Q4. SWAP TWO NUMBERS

echo "Enter the First Number: "
echo "Enter the Second Number: "
temp=\$a
a=\$b
b=\$temp
echo "First Number is now: \$a"
echo "Second Number is now: \$b"

## Q5. FIND THE LARGEST NUMBER

echo "Enter the First Number: "
echo "Enter the Second Number: "
echo "Enter the Third Number: "
if [ \$a -gt \$b ] && [ \$a -gt \$c ]
then
echo "\$a is the greatest!"
elif [ \$b -gt \$a ] && [ \$b -gt \$c ]; then
echo "\$b is the greatest!"
else
echo "\$c is the greatest!"
fi

## Q6. CHECK IF THE YEAR IS A LEAP YEAR OR NOT

echo "Enter the Year: "
rem=`expr \$y % 4`
if [ \$rem -eq 0 ]
then
echo "\$y is a leap year!"
else
echo "\$y is NOT a leap year!"
fi

## Q7. MAKE A CALCULATOR USING SWITCH CASE

echo "Enter the First Number:"
echo "Enter the Second Number:"
echo
echo "Options:"
echo "To Subtract, Enter 2"
echo "To Multiply, Enter 3"
echo "To Divide, Enter 4"
case \$ch in
1)
res=`expr \$a + \$b`
echo "Sum is: \$res"
;;
2)
res=`expr \$a - \$b`
echo "Remainder is: \$res"
;;
3)
res=`expr \$a \* \$b`
echo "Product is: \$res"
;;
4)
res=`expr \$a / \$b`
echo "Quotient is: \$res"
;;
esac

## Q8.INPUT STUDENT RESULT MARKS AND CATEGORIZEWHETHER IN FAIL, 1ST DIVISIONOR 2ND DIVISION

echo "Enter Final Marks: "
if [ \$res -ge 85 ]; then
echo "You are in First Division!"
elif [ \$res -ge 70 ]; then
echo "You are in Second Division!"
elif [ \$res -lt 40 ]; then
echo "You have FAILED!"
else
echo "No Division. AVERAGE"
fi

## Q9. FIND FACTORIAL OF A NUMBER

echo "Enter Number:"
f=1
while [ \$n -gt 0 ]
do
f=`expr \$f \* \$n`
n=`expr \$n - 1`
done
echo "Factorial is: \$f"

## Q10. FIND FIBONACCI SERIES

echo "Enter limiting number:"
num1=0
num2=1
echo -n "Fibonacci Series:"
echo -n " \$num1"
while [ \$n -gt 1 ]
do
temp=\$num2
num2=`expr \$num2 + \$num1`
num1=\$temp
echo -n " + \$num2"
n=`expr \$n - 1`
done
echo

## Q11. FIND REVERSE OF A NUMBER

echo "Enter the number:"
num=\$n
rev=0
while [ \$num -gt 0 ]
do
digit=`expr \$num % 10`
rev=`expr \$rev \* 10 + \$digit`
num=`expr \$num / 10`
done
echo "Reverse of \$n is \$rev"

## Q12. ENTER A FIVE DIGIT NUMBER AND CALCULATE THE SUM OF ITS DIGITS

echo "Enter the Number:"
sum=0
while [ \$num -gt 0 ]
do
digit=`expr \$num % 10`
sum=`expr \$sum + \$digit`
num=`expr \$num / 10`
done
echo "Sum of digits: \$sum"

## Q13. CHECK IF NUMBER IS A PRIME NO

echo "Enter the number:"
flag=1
i=2
while [ \$i -lt \$n ]
do
rem=`expr \$n % \$i`
if [ \$rem -eq 0 ]
then
flag=0
fi
i=`expr \$i + 1`
done
if [ \$flag -eq 0 ]
then
echo "Number is NOT Prime."
else
echo "Number is Prime."
fi