0% found this document useful (0 votes)
42 views

Maddy

The document contains programs and outputs for various arithmetic and logical operations in the Bash shell including: a calculator, string concatenation and comparison, summing numbers, checking if a number is Armstrong, calculating the Fibonacci series, factorial of a number, multiplication tables, finding the greatest of three numbers, summing random numbers, calculating the area of a circle, checking if a number is even or odd, calculating an employee's salary, and summing even numbers between 1 and a given limit.

Uploaded by

Madhan Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Maddy

The document contains programs and outputs for various arithmetic and logical operations in the Bash shell including: a calculator, string concatenation and comparison, summing numbers, checking if a number is Armstrong, calculating the Fibonacci series, factorial of a number, multiplication tables, finding the greatest of three numbers, summing random numbers, calculating the area of a circle, checking if a number is even or odd, calculating an employee's salary, and summing even numbers between 1 and a given limit.

Uploaded by

Madhan Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

ARITHMETIC OPREATION

Program:
echo " A simple calculator " echo " enter two number " read a b echo "1.addition 2.subtraction 3.multiplication 4.division 5.exit" echo " enter the choice for operation " 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) clear;; 6) exit;; esac echo $c

Output:

STRING CONCATINATION
Program:
echo "Enter the first string" read s1 echo "Enter the second string" read s2 echo "Concatenated string is:" $s1 $s2

output:

STRING COMPARISON

Program:
echo "Enter the first string" read s1 echo "Enter the second string" read s2 if [ $s1 == $s2 ] then echo "The string are equal" else echo "The string are not equal" fi

Output:

SUM OF N NUMBERS
Program:
echo " Enter the value" read n i=0 sum=0 while [ $i -lt $n ] do r=`expr $n % 10 ` n=`expr $n / 10 ` sum=`expr $sum + $r ` done echo $sum

Output:

ARMSTRONG NUMBER

Program:
echo "Enter the no." read n t=$n s=0 b=0 c=10 while [ $n -gt $b ] do r=`expr $n % $c` i=`expr $r \* $r \* $r` s=`expr $s + $i` n=`expr $n / $c` done echo $s if [ $s -eq $t ] then echo "Armstrong no." else echo "Not an armstrong no." fi

Output:

FIBONNACI SERIES 2
Program:
echo "Enter a number" read n a=-1 b=1 i=1 while [ $i -le $n ] do c=`expr $a + $b ` a=$b b=$c echo $c i=`expr $i + 1 ` done

Output:

FACTORIAL OF A NUMBER
Program:
echo "Enter the number" read no fact=1 i=1 while [ $i -le $no ] do fact=`expr $fact \* $i ` i=`expr $i + 1` done echo "the factorial of $no is $fact "

Output:

GENETRATE MULTIPLICATION FACTOR


Program:
echo "Enter the number" read no i=1 echo "The multiplication of $no " until [ $i -gt 10 ] do pro=`expr $i \* $no ` echo " $no * $i = $pro " i=`expr $i + 1` done

Output:

BIGGEST OF THREE NUMBERS


Program:
echo "Enter the 3 numbers" read a b c if ([ $a -gt $b ]&&[ $a -gt $c ]) then echo " $a is greater" else if ([ $b -gt $c ]) then echo " $b is greater" else echo " $c is greater" fi fi

Output:

SUM OF RANDOM NUMBERS


Program:

echo "Enter the number" read n i=0 sum=0 while [ $i -lt $n ] do echo "Enter the value" read n1 sum=`expr $sum + $n1 ` i=`expr $i + 1` done echo " sum : $sum "

Output:

AREA OF A CIRCLE

PROGRAM:
echo "Enter the radius of the circle:" read r a=$(((22/7)*$r*$r)) echo "AREA OF THE CIRCLE=$a"

Output:

THE GIVEN NUMBER IS ODD OR EVEN


PROGRAM:

echo "ENTER THE NUMBER :" read n r=`expr $n % 2` if [ $r -eq 0 ] then echo "THE GIVEN NUMBER IS EVEN" else echo "THE GIVEN NUMBER IS ODD" fi

Output:

Employees Salary Details

PROGRAM:

echo " Basic salary " read Basic da=`expr $Basic \* 10 / 100` hra=`expr $Basic \* 20 / 100` gross=`expr $Basic + $da + $hra ` echo "gross salary = $gross"

Output:

SUM OF EVEN NUMBERS

PROGRAM:
echo "Enter the upper limit" read n i=2 while [ $i -lt $n ] do sum=`expr $sum + $i` i=`expr $i + 2` done echo "Sum is:$sum"

Output:

You might also like