In this blog post, we will write C, C++, Python, and Java programs to calculate the area of different geometrical shapes based on the user's choice and input. We will have five geometrical shapes: circle, rectangle, triangle, square, and parallelogram. Users can choose the shape and provide the required input fields to calculate its area.
We will use the following formulas to calculate the area of the circle, rectangle, triangle, square, and parallelogram:
- Area of circle = 3.1459* radius*radius
The logic to calculate the area of the circle will be
- Area of the rectangle = length* breadth
The logic to calculate the area of the circle will be
- Area of a triangle (with three sides given a, b, and c) = Square root of [s(s-a)(s-b)(s-c)] , where s = (a+b+c)/2
The logic to calculate the area of the circle will be
- Area of a square = side*side
The logic to calculate the area of the circle will be
- Area of Parallelogram = base*height
The logic to calculate the area of the circle will be:
C Program
Here is a C program to calculate the area of a circle, rectangle, triangle, square, or parallelogram depending on a user's choice:
Output
C++ Program
Here is a C++ program to calculate the area of a rectangle, triangle, square, or parallelogram depending on a user's choice:
Output
Python Program
Here is a Python program to calculate the area of a rectangle, triangle, square, or parallelogram depending on a user's choice:
Output
Java Program
Here is a Java program to calculate the area of a rectangle, triangle, square, or parallelogram depending on a user's choice:
Output
Wrapping Up!
Here ends our tutorial on writing C, C++, Python, and Java programs to determine the area of a rectangle, triangle, square, or parallelogram. We have used a switch case in all programs and calculated the area of a shape depending on the input provided by users. You can also try without using a switch case.
We hope these programs have helped you understand how to calculate the area of other shapes.
People are also reading:
- Print the truth table for XY+Z
- Create a loading bar
- Print the Following Pattern
- Print the Following Triangle
- Calculate sum and average of three numbers
- Print three numbers in descending order
- Print given series:1 2 4 8 16 32 64 128
- Find quotient and remainder of two numbers
- Find Cube of a Number using Functions
- Convert a lowercase alphabet to uppercase or vice-versa using ASCII code
Leave a Comment on this Post