You are on page 1of 5

SIDDHANT BHALLA

19070124062

IT 3

ASSIGNMENT 5

1) GCD OF TWO NUMBERS


INPUT-
echo Enter two numbers with space in between
read a b
m=$a
if [ $b -lt $m ]
then
m=$b
fi
while [ $m -ne 0 ]
do
x=\`expr $a % $m\`
y=\`expr $b % $m\`
if [ $x -eq 0 -a $y -eq 0 ]
then
echo gcd of $a and $b is $m
break
fi
m=\`expr $m - 1\`
done

OUTPUT-

2) MULTIPLICATION TABLE

INPUT-
echo "which number to generate multiplication table"
  read number
  i=1
  while [ $i -le 10 ]
  do
  echo " $number * $i =`expr $number \* $i ` "
  i=`expr $i + 1`
  done

OUTPUT-

3) FIBONACCI SERIES

INPUT-

echo "How many number of terms to be generated ?"


read n
x=0
y=1
i=2
echo "Fibonacci Series up to $n terms :"
echo "$x"
echo "$y"
while [ $i -lt $n ]
do
i=`expr $i + 1 `
z=`expr $x + $y `
echo "$z"
x=$y
y=$z
done

OUTPUT-
4)PRIME NUMBER UPTO GIVEN TERM

INPUT-

#!/bin/bash
echo "Enter a limit"
read limit
echo "prime numbers upto $limit are :"
echo "1"
i=2
while [ $i -le $limit ]
do
flag=1
j=2
while [ $j -lt $i ]
do
rem=$(( $i % $j ))
if [ $rem -eq 0 ]
then
flag=0
break
fi
j=$(( $j+1 ))
done
if [ $flag -eq 1 ]
then
echo "$i"
fi
i=$(( $i+1 ))
done

OUTPUT-

OUTPUT-
5) TO CALCULATE AB

INPUT-
echo enter a and b
read a b
c=`expr $a \* $b`
echo $c

OUTPUT-

6) REVERSE OF A NUMBER

INPUT-echo enter n
read n
num=0
while [ $n -gt 0 ]
do
num=$(expr $num \* 10)
k=$(expr $n % 10)
num=$(expr $num + $k)
n=$(expr $n / 10)
done
echo number is $num

OUTPUT-

You might also like