echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
echo "Please enter your choice:"
read choice
echo "Enter the first value:"
read a
echo "Enter the second value:"
read b
case $choice in
1) sum=`expr $a + $b`
echo "Sum of $a and $b is " $sum
;;
2) diff=`expr $a - $b`
echo "Difference of $a and $b is " $diff
;;
3) prod=`expr $a \* $b`
echo "Product of $a and $b is " $prod
;;
4) div=`expr $a / $b`
echo "Divions of $a and $b is " $div
;;
*) echo "Invalid option selected!"
Esac
program to implement case structure
Output:
[csuser@localhost ~]$ vi ma
[csuser@localhost ~]$ chmod 777 ma
[csuser@localhost ~]$ ./ma
1. Addition
2. Subtraction
3. Multiplication
4. Division
Please enter your choice:
1
Enter the first value:
2
Enter the second value:
3
Sum of 2 and 3 is 5
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
echo "Please enter your choice:"
read choice
echo "Enter the first value:"
read a
echo "Enter the second value:"
read b
case $choice in
1) sum=`expr $a + $b`
echo "Sum of $a and $b is " $sum
;;
2) diff=`expr $a - $b`
echo "Difference of $a and $b is " $diff
;;
3) prod=`expr $a \* $b`
echo "Product of $a and $b is " $prod
;;
4) div=`expr $a / $b`
echo "Divions of $a and $b is " $div
;;
*) echo "Invalid option selected!"
Esac
program to implement case structure
Output:
[csuser@localhost ~]$ vi ma
[csuser@localhost ~]$ chmod 777 ma
[csuser@localhost ~]$ ./ma
1. Addition
2. Subtraction
3. Multiplication
4. Division
Please enter your choice:
1
Enter the first value:
2
Enter the second value:
3
Sum of 2 and 3 is 5
No comments:
Post a Comment