Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added area-calculator.sh in scripts
Signed-off-by: sejallgaikwad <[email protected]>
  • Loading branch information
sejallgaikwad committed Apr 29, 2023
commit f3bd53400ac0225925a685c6bcf0ac11a7259c0e
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ A collection of simple Bash scripts.
1. [Binary2Decimal.sh](scripts/binary2decimal.sh): convert Binary Number back to decimal
1. [Decimal2Hex.sh](scripts/dec2hex.sh): convert Decimal Number to Hex
1. [Hex2Decimal](scripts/hextodec.sh): convert Hex number back to Decimal
1. [Area-Calculator.sh](scripts/area-calculator.sh): area calculator of any shape

## Image manipulation

Expand Down
55 changes: 55 additions & 0 deletions scripts/area-calculator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# This script calculates the area of various shapes.

echo "What shape do you want to calculate the area of? Choose from the following:"
echo "1. Square"
echo "2. Rectangle"
echo "3. Circle"
echo "4. Rhombus"
echo "5. Triangle"

read choice

case $choice in
1)
echo "Enter the length of one side of the square:"
read length
area=$(echo "$length * $length" | bc)
echo "The area of the square is $area"
;;
2)
echo "Enter the length of the rectangle:"
read length
echo "Enter the width of the rectangle:"
read width
area=$(echo "$length * $width" | bc)
echo "The area of the rectangle is $area"
;;
3)
echo "Enter the radius of the circle:"
read radius
pi=$(echo "scale=10; 4*a(1)" | bc -l)
area=$(echo "$pi * $radius * $radius" | bc)
echo "The area of the circle is $area"
;;
4)
echo "Enter the length of one diagonal of the rhombus:"
read diagonal1
echo "Enter the length of the other diagonal of the rhombus:"
read diagonal2
area=$(echo "scale=2; ($diagonal1 * $diagonal2) / 2" | bc)
echo "The area of the rhombus is $area"
;;
5)
echo "Enter the base of the triangle:"
read base
echo "Enter the height of the triangle:"
read height
area=$(echo "scale=2; ($base * $height) / 2" | bc)
echo "The area of the triangle is $area"
;;
*)
echo "Invalid choice"
;;
esac
File renamed without changes.