0% found this document useful (0 votes)
3 views3 pages

Lab Linux

The document provides several shell script programs including one for generating the Fibonacci series, creating a multiplication table, performing simple arithmetic calculations, checking for Armstrong numbers, and determining if a number is a palindrome. Each program includes user input prompts and logic to execute the respective tasks. The scripts utilize basic control structures and arithmetic operations in bash.

Uploaded by

kindalkarammu
Copyright
© © All Rights Reserved
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)
3 views3 pages

Lab Linux

The document provides several shell script programs including one for generating the Fibonacci series, creating a multiplication table, performing simple arithmetic calculations, checking for Armstrong numbers, and determining if a number is a palindrome. Each program includes user input prompts and logic to execute the respective tasks. The scripts utilize basic control structures and arithmetic operations in bash.

Uploaded by

kindalkarammu
Copyright
© © All Rights Reserved
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/ 3

Program to Find Fibonacci Series using Shell Script

clear echo "Program to Find Fibonacci Series"

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

write a shell script program to generate multiplication table

echo "Enter a Number"

read n

echo "Enter Range"

read r

i=0

while [ $i -le $r ]

do

echo " $n x $i = `expr $n \* $i`"

i=`expr $i + 1`

done

Simple Arithmetic Calculator

 # !/bin/bash
echo "Enter Two numbers : "

read a

read b

# Input type of operation

echo "Enter Choice :"

echo "1. Addition"

echo "2. Subtraction"

echo "3. Multiplication"

echo "4. Division"

read ch

case $ch in

1)res=`echo $a + $b | bc`

;;

2)res=`echo $a - $b | bc`

;;

3)res=`echo $a \* $b | bc`

;;

4)res=`echo "scale=2; $a / $b" | bc`

;;

esac

echo "Result : $res"

Armstrong number

echo "Enter a number: "


read c

x=$c
sum=0
r=0
n=0
while [ $x -gt 0 ]
do
r=`expr $x % 10`
n=`expr $r \* $r \* $r`
sum=`expr $sum + $n`
x=`expr $x / 10`
done

if [ $sum -eq $c ]
then
echo "It is an Armstrong Number."
else
echo "It is not an Armstrong Number."
fi

Write a script to check whether a given number is palindrome or not

echo "Enter the number"

read n

number=$n

reverse=0

while [ $n -gt 0 ]

do

a=`expr $n % 10 `

n=`expr $n / 10 `

reverse=`expr $reverse \* 10 + $a`

done

echo $reverse

if [ $number -eq $reverse ]

then

echo "Number is palindrome"

else

echo "Number is not palindrome"

fi

You might also like