d. Exit
Enter choice
b
Enter number 7
number is prime
Do you want to continue press y/n y
a. Factorial
b. Prime or not
c. Odd or even
d. Exit
Enter choice
c
enter number 5 number is odd
Do you want to continue press y
a. Factorial
b. Prime or not
c. Odd or even
d. Exit
Enter choice
c
enter number 12
number is even
Do you want to continue press y
a. Factorial
b. Prime or not
c. Odd or even
d. Exit
Enter choice
2
wrong choice
Do you want to continue press y
a. Factorial
b. Prime or not
c. Odd or even
d. Exit
Enter choice
d
y/n
y/n
y/n
76. Program for printing user id of user whose uid >50.
$vi prg76
clear
cat /etc/passwd | cut -f3 -d ‘:’>aa
uid=50
while [ $uid -le 65535 ]
# 65535 is last user id
do
grep $uid aa>>bb
uid=‘expr $uid +1’
done
sort bb #
order by first digit
Sample Run
$sh prg76
500
501
502
51
65534
68
69
74
77
81
99
77. Program for swapping of two numbers.
$vi prg77
clear
echo Enter the first number
read a
echo Enter the second number
read b
c=$a
a=$b
b=$c
echo After swapping
echo first number is $a
echo second number is $b
Sample Run
$sh prg77
Enter the first number
5
Enter the second number
6
After swapping
first number is 6
second number is 5
78. Write a Program to check whether a number given by the user is zero, positive or negative.
$vi prg78
clear
echo Enter the Number
read x
if [ $x -gt 0 ]
then
echo x is Positive
elif [ $x -eq 0 ]
then
echo x is a Zero
else
echo x is Negative
fi
Sample Run
$sh prg78
Enter the Number
2
x is Positive
$sh prg78
Enter the Number
0
x is a Zero
$sh prg78
Enter the Number
-3
x is Negative
79. Program for checking the login id & password.
$vi prg79
clear
echo Enter the login id
read login
echo Enter the password
read password
if [ $login = root ]
then
if [ $password = redhat ]
then
echo You entered the correct login name and password
fi
else
echo login failed
fi
Sample Run
$sh prg79
Enter the login id
root
Enter the password
unix
login failed
$sh prg79
Enter the login id
root
Enter the password
redhat
You entered the correct login name and password
$sh prg79
Enter the login id
unix
Enter the password
redhat
login failed
80. Program to find the sum of numbers entered through command-line.
$vi prg80
clear
sum=0
for i in $*
do
sum=‘expr $sum + $i’
done
echo The sum of the given numbers is $sum
Sample Run
$sh prg80 30 40
The sum of the given numbers is 70
81. The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.
$vi prg81
clear
echo Enter length, breadth and radius
read length breadth radius
areaR=‘expr $length \* $breadth’
perimeterR=‘expr 2 \* \( $length + $breadth \)’
areaC=‘echo 3.14 \* $radius \* $radius |bc’
‘$areaR ‘$perimeterR ‘$areaC ‘$cirC
cirC=‘echo 2\* 3.14 \* $radius |bc’
echo ‘Area of rectangle = ‘$areaR
echo ‘Perimeter of rectangle = ‘$perimeterR
echo ‘Area of circle = ‘$areaC
echo ‘Circumference of circle = ‘$cirC
Sample Run
$sh prg81
Enter length, breadth and radius
20 5 5
Area of rectangle = 100
Perimeter of rectangle = 50
Area of circle = 78.50
Circumference of circle = 31.40
82. If a five digit number is input through the keyboard, write a program to calculate the sum of its digits.
$vi prg82
clear
echo Enter any five digit number
read num
d1=‘expr $num % 10’
num=‘expr $num / 10’
d2=‘expr $num % 10’
num=‘expr $num / 10’
d3=‘expr $num % 10’
num=‘expr $num / 10’
d4=‘expr $num % 10’
num=‘expr $num / 10’
d5=‘expr $num % 10’
sum=‘expr $d1 + $d2 + $d3 + $d4 + $d5’
echo Sum of digits = $sum
Sample Run
$sh prg82
Enter any five digit number
12345
Sum of digits = 15
83. If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit was made or loss incurred.
$vi prg83
clear
echo Enter cost price of the item
read cp
echo Enter selling price of the item
read sp
if [ $sp -gt $cp ]
then
echo Seller had made profit
profit=‘echo $sp - $cp | bc’
echo Profit = $profit
else
if [ $cp -gt $sp ]
then
echo Seller has incurred loss
loss=‘echo $cp - $sp | bc’
echo Loss = $loss
else
echo No profit, no loss
fi
fi
Sample Run
$sh prg83
Enter cost price of the item
1500
Enter selling price of the item
2000
Seller had made profit
Profit = 500
84. Write a program to calculate overtime pay of employees. Overtime is paid at the rate of Rs. 12.00 per hour for every hour worked above 40 hours. Assume that employees do not work for fractional part of an hour.
$vi prg84
Clear
Echo How many employees are there?
Read number
emp=1
while [ $emp -le number ]
do
echo enter working hours for employee number $emp
read hours
if [ $hours -gt 40 ]
then
otpay=‘expr \( $hours - 40 \) \* 12’ echo overtime pay = Rs.
$otpay
else
echo no overtime pay
fi
emp=‘expr $emp + 1’
done
Sample Run
$sh prg84
How many employees are there?
5
enter working hours for employee number 1