You need to know the Breadth 1, Breadth 2, and Height of to Trapezoid to calculate the area.
Variables:1. b1 : (Datatype int): to represent the breadth 1 of Trapezoid.
2. b2 : (Datatype int): to represent the breadth 2 of Trapezoid.
3. height : (Datatype long): to represent the height of Trapezoid.
4. area_of_trapezoid: (Datatype long): to store the result of the area of the Trapezoid being computed.
Functions:printf(): is used to display something on the console/screen. Format specifier %d in printf function is used to display an int variable on-screen and %ld for long. \n is used to add a new line
scanf(): is used to fetch data inputted by the user on the console/screen using the keyboard. %d in scanf is indicated that inputted text is of type int and %ld for long.
Formula:Area of Trapezoid : (height/2) x (b1 + b2);
/*
* 1000+ C programs + tutorials
*
*
* 8_calculate_area_of_trapezoid.c
*
*
* Created on: Oct 20, 2014
* Author: Code2care.org
*/
#include <stdio.h>
//#include <conio.h>
void main() {
int height;
int b1,b2; //breadth1 and breath2
long area_of_trapezoid;
// clrscr();
printf(" Program to calculate Area of a Trapezoid : \n\n");
printf(" Enter the Height of a Trapezoid : ");
scanf("%d", &height);
printf("\n\n Enter the Breadth1 value : ");
scanf("%d", &b1);
printf("\n\n Enter the Breadth2 value : ");
scanf("%d", &b2);
area_of_trapezoid = (height/2)*(b1+b2);
printf("\n\n Area of Trapezoid with Height as %d, Breadth1 as %d and Breadth2 as %d =
%ld",height,b1,b2,area_of_trapezoid);
// getch();
}
Output:
Program to calculate Area of a Trapezoid:
Enter the Height of a Trapezoid: 15
Enter the Breadth1 value : 30
Enter the Breadth2 value : 10
Area of Trapezoid with Height as 15, Breadth1 as 30 and Breadth2 as 10 = 280
The best way to learn C programming is to practice more and more programs. Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.
BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.
- Calculate Volume of Pyramid - C-Program
- Launch Notepad++ html document in any web browser - NotepadPlusPlus
- Sublime Text spell check shortcut - Sublime
- Download interrupted: Unknown Host dl-ssl.google.com Error Android SDK Manager - Android
- Android Launch! The connection to adb is down, and a severe error has occured - Android
- How to resolve Certificate Expired WhatsApp Error - WhatsApp
- Transfer files between Android and Mac OS X using usb cable - Mac-OS-X
- Make Bootstrap Button look like a link - Bootstrap
- Horizontally Center Align tag in HTML using CSS - CSS
- Android R Cannot Be Resolved To A Variable - Android
- Convert SQL to CSV in Notepad++ - NotepadPlusPlus
- Hide Scrollbar from Android Views - Android
- Error running 'app': No target device found. - Android-Studio
- PHP 301 Redirect Permanently - PHP
- How to enable Do Not Disturb mode for Notification Center in Mac OS X 10.10 Yosemite - Mac-OS-X