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: "
read a
read b
read c
read d
read e
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: "
read r
area=` expr 22 / 7 \* $r \* $r`
echo "Ans is $area"



Q3. CALCULATE THE SIMPLE INTEREST


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


Q4. SWAP TWO NUMBERS


echo "Enter the First Number: "
read a
echo "Enter the Second Number: "
read b
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: "
read a
echo "Enter the Second Number: "
read b
echo "Enter the Third Number: "
read c
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: "
read y
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:"
read a
echo "Enter the Second Number:"
read b
echo
echo "Options:"
echo "To Add, Enter 1"
echo "To Subtract, Enter 2"
echo "To Multiply, Enter 3"
echo "To Divide, Enter 4"
echo -n "Your Choice: "
read ch
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 CATEGORIZE
WHETHER IN FAIL, 1ST DIVISION
OR 2ND DIVISION



echo "Enter Final Marks: "
read res
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:"
read n
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:"
read n
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:"
read n
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:"
read num
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:"
read n
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

Comments