Professional Documents
Culture Documents
Write A Shell Script That Will Find The Area and Perimeter of A Rectangle Where Length and Breadth Are Given by The User
Write A Shell Script That Will Find The Area and Perimeter of A Rectangle Where Length and Breadth Are Given by The User
Write A Shell Script That Will Find The Area and Perimeter of A Rectangle Where Length and Breadth Are Given by The User
Write a shell script that will find the area and perimeter of a rectangle where length and breadth
are given by the user.
SOURCE CODE
echo "Enter the length: "
read length
echo "Enter the breadth: "
read breadth
area=$(($length * $breadth))
perimeter=$((2 * ($length+ $breadth)))
echo "Area of the rectangle is: " $area
echo "Perimeter of the rectangle is: " $perimeter
OUTPUT
Q2. Write a shell script that will check that a given integer number is EVEN or ODD.
SOURCE CODE
echo "Enter a number: "
read number
OUTPUT
Q3. Write a shell script that will find the largest among three given integer numbers.
SOURCE CODE
echo "Enter the first number: "
read num1
echo "Enter the second number: "
read num2
echo "Enter the third number: "
read num3
if [ $num1 -ge $num2 ] && [ $num1 -ge $num3 ];
then
echo "num1 is the largest number."
elif [ $num2 -ge $num1 ] && [ $num2 -ge $num3 ];
then
echo "num2 is the largest number."
else
echo "num3 is the largest number."
fi
OUTPUT
Q4. Write a shell script that will check that the given inter number [ max 5 digited] is a
PALLINDROME number or not.
SOURCE CODE
echo "Enter a number: "
read num
original_num=$num
rev=0
while [ $num -gt 0 ]
do
remainder=$(($num % 10))
rev=$((($rev * 10) + $remainder))
num=$(($num / 10))
done
if [ $original_num -eq $rev ]
then
echo "$original_num is a palindrome number."
else
echo "$original_num is not a palindrome number."
Fi
OUTPUT
Q5. Write a shell script that will check if the given integer number is PRIME or not. Modify the
script to find and print all prime numbers between a given range.
SOURCE CODE
echo "Enter a number:"
read number
if [ $number -lt 2 ]
then
echo "$number is not a prime number."
exit
fi
i=2
while [ $i -lt $number ]
do
if [ $((number % i)) -eq 0 ] # Arithmetic expression within double parentheses
then
echo "$number is not a prime number."
exit
fi
i=$((i + 1)) # Arithmetic expression for increment
done
echo "$number is a prime number."
OUTPUT