Saturday, 16 March 2013

CPL Exp.No.7b for OBS


Exp.No.7b – SUM OF FIVE NUMBERS FROM COMMAND LINE



Coding

# Read N numbers from the user with command line argument and display its sum
if [ $#  -eq 0 ]
then
echo "Enter the arguments properly" fi
sum=0;
n=$#
for i in $*
do
sum=`expr $sum + $i`
shift done
if [ $n -ne 0 ]
then echo "The sum of $n number(s) is $sum" fi

CPL Exp.No.7a for OBS


Exp.No.7a SUM OF FIRST FIVE NUMBERS USING FOR LOOP



Coding



# Find sum of first five numbers using for loop sum=0
for i in 1 2 3 4 5 do
sum=`expr $sum + $i`
done
echo "The sum of first five numbers is $sum"

CPL Exp.No.6c – MENU DRIVEN PROGRAM for OBS


Exp.No.6c – MENU DRIVEN PROGRAM



Coding



# Generate UNIX commands with menu driven program echo  " MENU "
echo  "1.List of files"
echo  "2.Today's Date" echo  "3.Process Status" echo  "4.Logged in Users"
echo  "5.Display the current working Directory" echo  "6.Quit"
echo  -n "Enter your choice" read ch
case "$ch" in
1) ls -l;;
2) date;;
3) ps;;
4) who;;
5) pwd;;
6) exit;;
*) echo "Invalid Choice" exit;;
esac

CPl Exp.No.6b for obs


Exp.No.6b – CHARACTER CLASSIFICATION



Coding

#Shell Program to classify char from Command Line char=$1
case "$char" in
[0-9] ) echo digit;;
[A-Z] ) echo Letter;;
? ) echo special letter;;
* ) echo enter a single character in command line;;
esac

CPL 6a Xperiment for OBS


Exp.No.6a ARITHMETIC OPERATIONS USING CASE - ESAC



Coding

echo "Menu"
echo "1.Addition" echo "2.Subtraction" echo "3.Multiplication" echo "4.Division"
echo  -n "Enter your choice" read ch
echo  -n "Enter the values for a and b:"
read a b
case  $ch  in
c=`expr $a  + $b`
echo "The sum is $c";;
2) c=`expr $a  - $b`
echo "The difference is $c";;
3) c=`expr $a \* $b`
echo "The product is $c";;
4)  c=`expr $a / $b`
echo "The quotient is $c";;
*) echo "Enter the correct choice";;
esac