Professional Documents
Culture Documents
Coding :
echo "enter the base "
read b
echo "enter the height
read h
echo "enter the radius "
read r
rarea=`expr $h \* $b`
phi=`expr 22 /7`
d=`expr $r \* $r`
carea=`expr $phi \* $d`
echo "the area of rectangle: $rarea"
echo "the area of circle : $carea"
Output:
Output:
[student40@fosslab shell]$ sh swap.sh
enter swap the value of a and b
24
42
Output:
Coding:
echo "enter the year"
read y
if [ ` expr $y % 4 ` -eq 0 ]
then
echo "the year is a large year"
else
echo "the year is not a leap year"
fi
Output:
Arithmetic operation
Coding:
echo "enter two number"
read a b
echo "what do you want to do?(1to5)"
echo "1) sum"
echo "2) difference"
echo "3) product"
echo "4) quotient"
echo "5)remainder"
echo "enter your choice"
read n
case "$n" in
1) echo "the sum of $a and $b is`expr $a + $b`";;
2)echo "the differnce between $a and $b is`expr $a - $b`";;
3)echo "the product of the $a and $b is`expr $a \* $b`";;
4)echo "the qoutient of $a by $b is`expr $a / $b`";;
5)echo "the remainder of $a by $b is `expr $a % $b`";;
esac
Output:
[student40@fosslab shell]$ sh maths.sh
enter two number
23
what do you want to do?(1to5)
1) sum
2) difference
3) product
4) quotient
5)remainder
enter your choice
1
the sum of 2 and 3 is5
[student40@fosslab shell]$ sh maths.sh
enter two number
23
what do you want to do?(1to5)
1) sum
2) difference
3) product
4) quotient
5)remainder
enter your choice
2
the differnce between 2 and 3 is-1
[student40@fosslab shell]$ sh maths.sh
enter two number
34
what do you want to do?(1to5)
1) sum
2) difference
3) product
4) quotient
5)remainder
enter your choice
3
The product between 3 and 4 is 12
Fibonacci series
Coding:
Output:
[student40@fosslab shell]$ sh fibonacci.sh
enter the limit
8
the fibonacci series is
0
1
1
2
3
5
8
13
Palindrome or Not
Coding:
echo "palindrome"
echo "enter the number"
read x
n=$x
b=0
while [ $x -ne 0 ]
do
a=`expr $x % 10`
b=`expr $b \* 10 + $a`
x=`expr $x / 10`
done
if [ $n -eq $b ]
then
echo "$n is a palindrome"
else
echo "$n is not palindrome"
fi
Output:
Coding:
echo "enter the number"
read n
t=0
i=`expr $n - 1`
while [ $i -ge 2 ]
do
p=`expr $n % $i`
if [ $p -eq 0 ]
then
t=`expr $t + 1`
fi
i=`expr $i - 1`
done
if [ $t -eq 0 ]
then
echo "it is a prime number"
else
echo "it is not a prime number"
fi
Output:
[student40@fosslab shell]$ sh prime.sh
Coding:
echo "enter x"
read x
echo "enter n"
read n
sum=1
i=1
while [ $i -le $n ]
do
sum=`expr $sum \* $x`
i=`expr $i + 1`
done
echo "the value of x^ n is $sum"
Output:
[student40@fosslab shell]$ sh value.sh
enter x
4
enter n
3
the value of x^ n is 64.
coding:
echo "enter two numbers"
read a b
a=`expr $a + $b`
b=`expr $a - $b`
a=`expr $a - $b`
echo $a $b
Output:
[student40@fosslab shell]$ sh arithematic.sh
enter two numbers
12 10
10 12
Armstrong Or Not
Coding:
echo "enter the number"
read n
sum=0
x=$n
while [ $n -gt 0 ]
do
y=`expr $n % 10`
z=`expr $y \* $y \* $y`
sum=`expr $sum \+ $z`
n=`expr $n / 10`
done
if [ $x -eq $sum ]
then
echo "it is a armstrong number"
else
echo "it is not a armstrong number "
fi
Output:
[student40@fosslab shell]$ sh armstrong.sh
enter the number
4
it is not a armstrong number
[student40@fosslab shell]$ sh armstrong.sh
enter the number
1
it is a armstrong number
Reverse of a Number
Coding:
echo "enter the number"
read n
r=0
while [ $n -gt 0 ]
do
a=`expr $n % 10`
r=`expr $r \* 10 \+ $a`
n=`expr $n / 10`
done
echo "the reverse is $r"
Output:
[student40@fosslab shell]$ sh reverse.sh
enter the number
23
the reverse is 32