Program to calculate the area and perimeter of a trapezoid
Aug 25, 2023 pm 08:37 PMA trapezoid is a quadrilateral with at least one pair of sides parallel to each other. The area and perimeter of a trapezoid can be calculated using the following formula:
Perimeter = sum of all sides
Area = ½ x (sum of lengths of parallel sides) x vertical line between parallel sides Distance
Code Logic - The code will use 5 variables for all sides of the trapezoid and 1 variable for the vertical distance between two parallel sides. For the area variable calculation we will take a floating point variable which will be initialized with that value. To calculate it we will use the formula "½ x (sum of lengths of parallel sides) x perpendicular distance between parallel sides". For perimeter calculation, the variable is assigned the expression "(sum of all sides)".
The following code shows the program to calculate the area and perimeter of a trapezoid,
Example
Live demonstration
#include <stdio.h> int main() { int a = 2 , b = 3 , c = 5 , d = 4, h = 5; float area, perimeter; printf("The sides of trapezium are %d , %d , %d , %d </p><p>", a,b,c,d); printf("Distance between two parallel sides is %d </p><p>", h); perimeter = a+b+c+d; area = 0.5 * (a + b) * h ; printf("Perimeter of the trapezium is %.1f</p><p>", perimeter); printf("Area of the trapezium is: %.3f", area); return 0; }
Output
The sides of trapezium are 2 , 3 , 5 , 4 Distance between two parallel sides is 5 Perimeter of the trapezium is 14.0 Area of the trapezium is: 12.500
The above is the detailed content of Program to calculate the area and perimeter of a trapezoid. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the types of values returned by c language functions? What determines the return value?

C language function format letter case conversion steps

What are the definitions and calling rules of c language functions and what are the

Where is the return value of the c language function stored in memory?

How does the C Standard Template Library (STL) work?

How do I use algorithms from the STL (sort, find, transform, etc.) efficiently?
