Professional Documents
Culture Documents
Practical 3
AIM: Write a shell script to generate marksheet of a student. Take 3 subjects,
calculate and display total marks, percentage and Class obtained by the
student.
Solution:
echo "*****************"
read os
read cpp
read java
echo "*****************"
percentage=`expr $total / 3`
if [ $percentage -ge 60 ]
then
then
then
Practical-4
Solution
fact=1
read -p "Enter a number to find its factorial : " n
#if entered value is less than 0
if [ $n -le 0 ]
then
echo "invalid number"
exit
fi
#logic for finding factorial
a=$n
while [ $a -ge 1 ]
do
fact=`expr $fact \* $a`
a=`expr $a - 1`
done
echo "Factorial of $n is $fact"
Practical-5
AIM: Write a shell script which will accept a number b and display first n prime
numbers as output.
Solution:
m=2
while [ $m -le $n ]
do
i=2
flag=0
while [ $i -le `expr $m / 2` ]
do
then
flag=1
break
fi
i=`expr $i + 1`
done
if [ $flag -eq 0 ]
then
echo $m
fi
m=`expr $m + 1`
done
Practical: 6
AIM: Write a shell script which will generate first n Fibonacci numbers like: 1, 1, 2, 3,
5, 13,...
Solution: