In this tutorial you will learn about the C Program to Find Area of a Trapezoid and its application with practical example.
C Program to Find Area of a Trapezoid
In this tutorial, we will learn to create a C program that will Find the Area of a Trapezoid in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic operations in C programming.
What is a Trapezoid?
The Trapezoid is a four-sided shape that has two sides that are parallel and two sides that are not parallel. Here, the shape has two different bases and the height for the trapezoid.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input height and the two bases of the <strong>Trapezoid </strong>from the user. 3. <strong>C</strong><strong>alculating the Area of a Trapezoid </strong>using the arithmetic expressions. 4. Printing the area of the <strong>Trapezoid</strong>. 5. End the program. |
Program description:-
In this tutorial, we will create a program, that will find the Area of the Trapezoid. we will First, take the base 1 and 2 of the Trapezoid, then the height of the Trapezoid from the user. Then we will calculate the area of the Trapezoid using arithmetic expressions / the formulae for the area of the Trapezoid. At last, we will print the Area of the Trapezoid.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* C Program to find area of a Trapezoid */ #include<stdio.h>//including the header file int main()//body of the main function. { //defining the required variabled for the program. float bs1, bs2, ht, ar, med; //bs1 = it will hold the input value of base 1. //bs2 = it will hold the input value of base 2. //ht = it will hold the height of the Trapezoid. //Taking the bases and the height of the Trapezoid by the user. printf("\n Please Enter two bases and height of the Trapezoid \n"); //Scanning the input bases and the height from the user scanf("%f %f %f", &bs1, &bs2, &ht); //calculating the Area of the Trapezoid ar = 0.5 * (bs1 + bs2) * ht; //calculating the Median of a Trapezoid med = 0.5 * (bs1+ bs2); //printing the area of the Trapezoid printf("\n Area of a Trapezoid = %.2f \n", ar); //printing the area of the Trapezoid printf("\n Median of a Trapezoid = %.2f \n", med); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- bs1 = it will hold the input value for the base 1of the Trapezoid.
- bs2 = it will hold the input value for the base 2 of the Trapezoid.
- ar = it will hold the value of the area of the Trapezoid.
Taking the input bases and the height of the Trapezoid.
Calculating the area of the Trapezoid.
Printing the area of the Trapezoid.