adp 2
adp 2
2 A
AIM:
DESCRIPTION:
statements conditionally.
SYNTAX: if [expression]
then statements
fi
options
SYNTAX: if [expression]
then
else
fi
Statement(s)
Statement
do
Statement (5)
done
(d) for loop:
The for loop operates on list of items it repeals a set of commands for
every
item in a list.
do
Statement(s)
done.
Programs :
AIM:
ALGORITHM:
1. Start
6. End
PROGRAM:
read age
if [ $age -ge 18 ]
then
fi
OUTPUT :
AIM:
ALGORITHM:
1. Start
6. End.
PROGRAM:
read mark
if [ $mark -ge 90 ]
then
echo Your Grade is A.
then
then
then
then
else
Fi
OUTPUT :
AIM:
1. Start
6. End.
PROGRAM:
read y
c=$((y%4))
if [ $c -eq 0 ]
then
else
Fi
OUTPUT :
d) To find the factorial of a given number using white and for loop
AIM:
To find the factorial of a given number using while and for loop
1. Start
6. End.
PROGRAM:
read num
n=$num
fact=1
while [ $n -gt 0 ]
do
fact=$((fact * n))
n=$((n – 1))
done
OUTPUT :
ALGORITHM:
1. Start
4. using for loop assign i=1; i<=num, itt (in for loop)
7. End.
PROGRAM:
echo Enter th
read num
fact=1
for ((i=1;i<=num;i++))
do
fact=$((fact * i))
done
OUTPUT :
AIM:
ALGORITHM:
1. Start
2. Get a number
3. Use white loop to compute the fibonacci by using the below formula.
4. fibo = $((a+b))
6. End.
PROGRAM:
read n
f=1
j=0
echo $j
echo $f
do
k=$((j \+ f))
12 j=$f
f=$k
echo $k
done
OUTPUT :
f) To find the greatest of three numbers using if elif...if
AIM:
ALGORITHM:
1. Start
2. Declare 3 numbers.
3. if 'a' is greater than 'b' and 'c', 'a' is larger else if 'b' is more than 'a' and
'c',
'b' is greater else i 'c' is more than 'a' and 'b','c' is greater
6. End.
PROGRAM:
read a
read b
read c
then
echo a is greatest
elif test $b -gt $c
then
echo b is greatest
else
echo c is greatest
fi
OUTPUT :
RESULT :
executed successfully.