OS Programs
OS Programs
RESULT:
Thus, the program has been executed successfully without any
errors
PROGRA
echo “Enter the Principal amount:”
read p
echo “Enter the Number of
years:” read n
echo “Enter the Rate of
Interest:” read r
echo “SI=$(($p*$n*$r/100))
OUTPU
Enter the Principal Amount:
25000
Enter the Number of
years: 5
Enter the Rate of
interest: 5
SI= 6250
RESULT:
Thus, the program has been executed successfully without any
PROGRA
echo “Enter the String:”
read s1
echo “Enter the String:”
read s2
if [ $s1=$s2 ]
then
echo “Both strings are same”
else
echo “Both strings are not same”
fi
OUTPU
CASE 1:
Enter the String:
Hi
Enter the
String:
Welcome
Both strings are not same
CASE 2:
Enter the
String:
Hi
Enter the String:
Hi
Both strings are same
RESULT:
Thus, the program has been executed successfully without any
PROGRA
a=10
b=20
val=`exp $a+$b`
echo ”a+b: $val”
val=`exp $a-$b`
echo ”a-b: $val”
val=`exp $a*$b`
echo ”a*b: $val”
val=`exp $a/$b`
echo ”a/b: $val”
val=`exp $a%$b`
echo ”a%b:
$val” if [ $a==$b
] then
echo ”a is equal to b”
fi
if [ $a!=$b ]
then
echo “a is not equal to b”
fi
OUTPU
a+b: 30
a-b: -10
a*b: 200
a/b: 2
a%b: 0
a is equal to b
RESULT:
Thus, the program has been executed successfully without any
PROGRA
echo “Enter a Number:”
read n
fact=1
while [ $n -gt 1 ]
do fact=$
((fact*n)) n=$
((n-1))
done
echo “Factorial is $fact”
OUTPU
Enter a
6
Factorial is 720
RESULT:
Thus, the program has been executed successfully without any
PROGRA
echo “Enter a Number:”
read n
i=1
sum=0
while [ $i -le $n ]
do sum=$
((sum+i)) i=$
((i+1))
done
echo “Sum from 1to $n is $sum”
OUTPU
Enter a Number:
5
Sum from 1 to 5 is 15
RESUL
Thus, the program has been executed successfully without any
PROGRA
echo “Enter the Number of terms:
read n
a=0
b=1
echo “The Fibonacci Series is”
for ((i=0, i<n, i++))
do
echo -n ”$a”
fn=$((a+b))
a=$b
b=$fn
done
OUTPU
Enter the Number of terms:
10
The Fibonacci series is
0 1 1 2 3 5 8 13 21 34
RESUL
Thus, the program has been executed successfully without any
PROGRA
echo “Enter the Number:”
read n
l=${n}
sum=0
num=$n
while [ $n -ne 0 ]
do rem=$((n
%10))
n=$((n//10))
pow=1
for ((j=0, j<l, j++))
do pow=$
((paw*rem)) done
sum=$((sum+pow))
done
if [ $sum -eq $num ]
then
echo “$num is an Armstrong Number”
else
echo “$num is not an Armstrong Number”
fi
OUTPU
Enter a Number:
153
153 is an Armstrong Number
RESULT:
Thus, the program has been executed successfully without any
PROGRAM
echo “Enter a string:”
read input
reverse=” “
len=${#input}
for ((i=$len-1, i<0, i++))
do
reverse=” $reverse ${input:
$i:1}” done
if [ $input==$reverse
] then
echo “$input is a palindrome”
else
echo “$input is not a palindrome”
fi
OUTPU
Enter a
string:
Malayalam
Malayalam is a palindrome
RESULT:
Thus, the program has been executed successfully without any
PROGRAM:
echo “Enter n1:”
read a
echo “Enter n2:”
read b
echo “Enter n3:”
read c
if [ $a -gt $b ] && [ $a -gt $c]
then
echo “$a is largest”
elif [ $b -gt $c ]
echo “$b is largest””
else
echo “$c is largest”
fi
OUTPU
Enter n1:
20
Enter n2:
10
Enter n3:
25
25 is largest
RESULT:
Thus, the program has been executed successfully without any
PROGRA
echo “Enter Two Number:”
read a b
m=$a
if [ $b -lt $m ]
then
m=$b
fi
while [ $m -ne 0 ]
do
x=$((a%m))
y=$((b%m))
if [ $x -eq 0 -a $y -eq 0 ]
then
echo “GCD of $a and $b is $m”
break
fi
m=$((m-1))
done
OUTPU
Enter Two
Number: 7 11
GCD of 7 and 11 is 11
RESULT:
Thus, the program has been executed successfully without any
PROGRA
echo “Enter length and breadth:”
read l b
area=$((l*b)) perimeter=$
((2*(l+b)))
echo “Area of the Rectangle is $area squared units”
echo “Perimeter of the Rectangle is $perimeter
units”
OUTPU
Enter the length and
breadth: 2 5
Are of the Rectangle is 10 squared
units Perimeter of the Rectangle is 7
units
RESULT:
Thus, the program has been executed successfully without any
PROGRA
echo “Enter the Number:”
read n
i=2
flag=0
while [ $i -le $((n/2)) ]
do
if [ $((n%1)) -eq 0 ]
then
flag=1
fi
i=$((i+1))
done
if [ $flag -eq 1 ]
then
echo “The number is not prime”
else
echo “The number is prime”
fi
OUTPU
Enter the Number:
7
The number is prime
RESULT:
Thus, the program has been executed successfully without any
PROGRAM:
echo “Enter Table
Number:” read n
echo “Enter Number of
Terms:” read t
for ((i=1, i<=t, i++))
do
echo “$i x $n=$((i*n))”
done
OUTPU
Enter Table
Number: 5
Enter Number of
Terms:
5
1x5=5
2 x 5 =10
3 x 5 =15
4 x 5 =20
5 x 5 =25
RESULT:
Thus, the program has been executed successfully without any
INDEX
Sl.No DATE PROGRAM NAME PAGE NO. SIGN