You are on page 1of 7

FACTORIAL OF A GIVEN NUMBER echo "FACTORIAL" echo read n f=1 for i in 1 2 3 4 5 do f=`expr $f \* $i` i=`expr $i + 1` done echo "FACTORIAL"

echo The fact is $f echo echo read n f=1 i=1 until [ $i -gt $n ] do f=`expr $f \* $i` i=`expr $i + 1` done echo The fact is $f echo (OR) echo "FACTORIAL" echo read n f=1 i=1 while [ $i -le $n ] do f=`expr $f \* $i` i=`expr $i + 1` done echo The fact is $f echo FIBONACCI SERIES tput clear echo "Enter the value of n:" read n

for((i=1;i<=n;i++)) do f=`expr $f \* $i` i=`expr $i + 1` done (OR)

f1=0 f2=1 echo "Sum of the Series" echo $f1 for((i=0;i<n;i++)) do echo $f2 f3=$f1 f1=$f2 f2=`expr $f3 + $f2` done echo GREATEST OF TWO NUMBERS clear read a read b if [ $a -gt $b ] then echo $a is greater else echo $b is greater fi echo GREATEST OF THREE NUMBERS tput clear read a read b read c if [ \( $a -gt $b \) -a \( $a -gt $c \) ] then echo $a is a greatest number elif [ $b -gt $c ] then echo $b is a greatest number else echo $c is a greatest number fi echo SMALLEST OF THREE NUMBERS tput clear read a

read b read c if [ \( $a -lt $b \) -a \( $a -lt $c \) ] then echo $a is a smallest number elif [ $b -lt $c ] then echo $b is a smallest number else echo $c is a smallest number fi echo SUM OF N EVEN NUMBERS echo Enter the value of n read n sum=0 i=2 while [ $i -le $n ] (OR) for ((i=2;i<=n;i+=2)) (OR) until [ $i gt $n ] do sum=`expr $sum + $i` i=`expr $i + 2` done echo echo The sum of even numbers is $sum SUM OF N ODD NUMBERS i=1 while [ $ I le $n ] do sum=`expr $sum + $i` i=`expr $i + 2` done SUM OF FIRST N EVEN NUMBERS echo Enter the value of n read n sum=0 i=1 j=2 while [ $i -le $n ] (OR) until [ $i gt $n ] (OR) for((i=1;i<=n;i++)) do sum=`expr $sum + $j` i=`expr $i + 1`

j=`expr $j + 2` done echo echo The sum of even numbers is $sum BASIC SALARY echo Enter basic salary read bs echo if [ $bs -lt 1500 ] then hra=`echo $bs \* 10 / 100 | bc` da=`echo $bs \* 90 / 100 | bc` else hra=500 da=`echo $bs \* 98 /100 | bc` fi echo gs=`echo $bs + $hra + $da | bc` echo Gross Salary = Rs.$gs PRIME OR NOT read n i=2 while [ $i -le $n ] do if [ `expr $n % $i` -eq 0 ] then break fi i=`expr $i + 1` done if [ $n -eq $i ] then echo "Prime" else echo "Not Prime" fi PALINDROME OR NOT clear read n t=$n d=0

while [ $n -gt 0 ] do r=`expr $n % 10` d=`expr $d \* 10 + $r` n=`expr $n / 10` done if [ $d -eq $t ] then echo palind else echo NTP fi echo ARITHMETIC OPERATION clear read x read y ch=1 while [ $ch -ne 6 ] do cat << a 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Modulus 6. Exit Enter Ur Choice: a read ch case $ch in 1) clear z=`expr $x + $y` echo $z ;; 2) clear z=`expr $x - $y` echo $z ;; 3) clear

z=`expr $x \* $y` echo $z ;; 4) clear z=`expr $x / $y` echo $z ;; 5) clear z=`expr $x % $y` echo $z ;; 6) exit ;; esac done

DISPLAY THE USER LIST tput clear ch=1 while [ $ch -ne 6 ] do cat << a 1. Display the list of user 2. Display the processors of user 3. Display the current date 4. Display the current list of user using 5. Display all the above options 6. Exit Enter Ur Choice: a read ch case $ch in 1) clear who ;; 2) clear ps

;; 3) clear date ;; 4) clear who -q ;; 5) clear who ps date who -q ;; 6) exit ;; esac done PERFECT OR NOT clear echo "PERFECT OR NOT" read n sum=0 for((i=1;i<n;i++)) do a=`expr $n % $i` if [ $a -eq 0 ] then sum=`expr $sum + $i` fi done if [ $sum -eq $n ] then echo "PERFECT NUMBER" else echo "NOT PERFECT NUMBER" fi echo

You might also like