0% found this document useful (0 votes)
40 views9 pages

G8 of 3 Nos

The document contains summaries of several Bash shell programs that perform tasks like: 1) Finding the greatest of three numbers. 2) Calculating the factorial of a given number. 3) Computing the sum of odd numbers up to a given value. 4) Generating Fibonacci numbers up to a limit. 5) Implementing an arithmetic calculator. 6) Converting between Fahrenheit and Celsius temperatures. 7) Checking if a given year is a leap year. Each program summary includes the program code, its expected output, and a brief description of what the program does.

Uploaded by

Lokkesh Krishna
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views9 pages

G8 of 3 Nos

The document contains summaries of several Bash shell programs that perform tasks like: 1) Finding the greatest of three numbers. 2) Calculating the factorial of a given number. 3) Computing the sum of odd numbers up to a given value. 4) Generating Fibonacci numbers up to a limit. 5) Implementing an arithmetic calculator. 6) Converting between Fahrenheit and Celsius temperatures. 7) Checking if a given year is a leap year. Each program summary includes the program code, its expected output, and a brief description of what the program does.

Uploaded by

Lokkesh Krishna
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

GREATEST AMONG THREE NUMBERS

PROGRAM:
echo enter 3 numbers read a b c if [ $a -gt $b -a $a -gt $c ] then echo a is greatest elif [ $b -gt $c ] then echo b is greatest else echo c is greatest fi

OUTPUT:
[exam@fosslab shamu]$shamu.sh Enter 3 nos 269 C ia greatest

FACTORIAL OF A GIVEN NUMBER

PROGRAM:
echo Enter the number read n i=1 f=1 while [ $i -lt $n ] do f=`expr $f \* $i` i=`expr $i + 1` done echo Factorial = $f

OUTPUT:
[exam@fosslab shamu]$sh fac.sh Enter the number 5 Factorial=24

SUM OF ODD NUMBERS UPTO N

PROGRAM:
x=1 sum=0 read n while [ $x -lt $n ] do sum=`expr $sum + $x` x=`expr $x + 2` done echo Sum is $sum

OUTPUT:
[exam@fosslab shamu]$sh sum.sh 4 Sum is 4

GENERATION OF FIBONACCI NUMBERS

PROGRAM:
echo enter the Limit p=-1 q=1 read n I=1 while [ $I le $n ] do r= `expr $p + $q` echo $r p=`expr $q` q=`expr $r` I=`expr $I + 1` done

OUTPUT:
[exam@fosslab shamu]$sh fibo.sh Enter the limit 4 0 1 1 2

IMPLEMENT THE ARITHMETIC CALCULATOR

PROGRAM:
echo Enter 2 numbers read a b echo 1-ADD 2-SUB 3 MUL 4-MOD 5-EXIT read op case $op in 1)c=`expr $a + $b`;; 2)c=`expr $a - $b`;; 3)c=`expr $a \* $b`;; 4)c=`expr $a % $b`;; 5)exit esac echo $c

OUTPUT:
[exam@fosslab shamu]$sh cal.sh Enter 2 nos 5 6 1-add 11

CONVERSION OF FAHRENHEIT TO DEGREE CENTIGRADE

PROGRAM:
echo Enter Farein temp read f a=`expr $f - 32` b=`expr $a \* 5` c=`expr $b / 9` echo $a $b $c

OUTPUT: [exam@fosslab shamu[$sh degree.sh Enter farein temp 43 11 55 6

CHECK WHETHER THE GIVEN YEAR IS LEAP YEAR OR NOT

PROGRAM:
yy=0 isleap="false" echo -n "Enter year (yyyy) : " read yy if [ $((yy % 4)) -eq 0 ] ; then isleap=true elif [ $((yy % 400)) -eq 0 ] ; then isleap="true" elif [ $((yy % 100)) -eq 0 ] ; then isleap="false" fi if [ "$isleap" == "true" ]; then echo "$yy is leap year" else echo "$yy is NOT leap year" fi

OUTPUT:
[exam@cselab1 shamu]$sh leap.sh Enter year (yyyy):2012 2012 is leap year 1993 is not a laep year

You might also like