Operating System Part3
Operating System Part3
read n
f=1
for((i=1;i<=n;i++))
do
f=$((f*i))
done
echo Factorial is $f
1+1/2+1/3……+1/n SERIES
echo Enter a number
read n
i=1
sum=0
while [ $i -le $n ]
do
i=`expr $i + 1`
done
i=1
while [ $i -le 5 ]
do
echo -e "$a\c"
if [ $i -eq 1 ] then
echo -e ".\c"
fi
i=`expr $i + 1`
done
echo
BINARY TO HEXADECIMAL
read n
j=30
flag=0
tem=2
while [ $i -ne $j ]
do
temp=`echo $i`
do
temp=`expr $temp - 1`
n=`expr $i % $temp`
then
flag=1
fi
done
if [ $flag -eq 0 ]
then
echo $i
else
flag=0
fi
i=`expr $i + 1`
done
PRIME NO
echo Enter a number
read n
i=2
flag=0
while [ $i -lt $n ]
do
m=`expr $n % $i`
if [ $m -eq $flag ]
then
echo Not Prime
exit
else
i=`expr $i + 1`
fi
done
echo Prime
FIND THE NUMBER OF WORDS IN A STRING
echo Enter a text
read text
w='echo $text|wc-w’
echo words=$w
REVERSE NUMBER
echo Enter a number
read n
rev=0
while [ $n -gt 0 ]
do
r=`expr $n % 10`
rev=`expr $rev \* 10 + $r`
n=`expr $n / 10`
done
echo The reverse number is $rev
LEAP-YEAR CHECKING
echo enter the year
read y
a=`expr $y % 4`
b=`expr $y % 100`
c=`expr $y % 400`
if [ $a -eq 0 -a $b -ne 0 -o $c -eq 0 ]
then
echo $y is leap year
else
echo $y is not leap year
fi
Sum of n natural no
echo Enter a number
read n
sum=0
for((i=1;i<=n;i++))
do
sum=`expr $sum + $i`
done
echo The sum is $sum
Sum of squre of n natural number
echo Enter a number
read n
sum=0
r=0
for((i=1;i<=n;i++))
do
r=`expr $i \* $i`
sum=`expr $sum + $r`
done
echo The sum of squre is $sum
Sum of cube of n natural number
echo Enter a number
read n
sum=0
r=0
for((i=1;i<=n;i++))
do
r=`expr $i \* $i \* $i`
sum=`expr $sum + $r`
done
echo The sum of cube is $sum
Bubble sort
echo "Enter Values That You Want To Sort:"
read vals
set -- $vals
n=$#
k=0
for val in $*
do
a[$k]=$val
((k++))
done
flag=1
do
flag=0
do
then
temp=${a[$j]}
a[$j]=${a[$j+1]}
a[$j+1]=$temp
flag=1
fi
done
done
do
done
echo
Insertion sort
echo "enter the number"
read n
for((i=0;i<n;i++))
do
read arr[$i]
done
for((i=1;i<n;i++))
do
j=$i-1
temp=${arr[$i]}
do
arr[$j+1]=${arr[$j]}
j=$j-1
done
arr[j+1]=$temp
done
for((i=0;i<n;i++))
do
echo ${arr[$i]}
done
Selection sort
echo "enter the number"
read n
for((i=0;i<n;i++))
do
read arr[$i]
done
for((i=0;i<n-1;i++))
do
small=${arr[$i]}
index=$i
for((j=i+1;j<n;j++))
do
if((arr[j]<small))
then
small=${arr[$j]}
index=$j
fi
done
temp=${arr[$i]}
arr[$i]=${arr[$index]}
arr[$index]=$temp
done
for((i=0;i<n;i++))
do
echo ${arr[$i]}
done
Concatenation of two strings
echo Enter 1st string
read x
read y
z=$x$y
read n
i=0
for((i=0;i<n;i++))
do
read num[$i]
done
pos=0
neg=0
zer=0
for((i=0;i<n;i++))
do
if [ ${num[$i]} -gt 0 ]
then
pos=`expr $pos + 1`
then
neg=`expr $neg + 1`
else
zer=`expr $zer + 1`
fi
done
echo Positive=$pos
echo Negative=$neg
echo Zero=$zer
Common Multiple of two numbers
echo "Enter the first number : "
read a
read b
if [ $a -gt $b ]
then
num=$a
den=$b
else
num=$b
den=$a
fi
while [ $r -ne 0 ]
do
num=$den
den=$r
done
gcd=$den
lcm=`expr $a \* $b / $gcd`
echo " The LCM of $a and $b is : $lcm"
Length of a String
echo Enter the string
read str
read var
read p
read n
echo ${var:$p}
echo ${var:$p:$n}
Alternative digits of 5 digit number
echo Enter a 5 digit number
read num
n=1
while [ $n -le 5 ]
do
echo $a
n=`expr $n + 2`
done
Decimal to Octal conversion
echo Enter a decimal number
read n
read n
sq=0
r=0
sq=`expr $n \* $n`
if [ $n -eq $r ] then
echo Automorphic
else
echo Non-Automorphic
fi
Simple Interest
echo Enter principal
read p
read n
read r
i=`expr $n \* $p \* $r`
i=`expr $i / 100`
read s
read leng
read brea
read radius
sarea=`echo $s \* $s | bc`