Program to compute the area of Trapezoid

Problem statement:-  Program to compute the area of the Trapezoid.

Formula:

Area Of Trapezoid(A):


where a and b=base length of the Trapezoid
           h= height of the Trapezoid

 Data requirement:-

   Input Data:- a, b, h

  Output Data:- area

Program in C

Here is the source code of the C Program to compute the area of the Trapezoid.

Code:

#include<stdio.h>
#include<math.h>
int main()
{
    printf("Enter the value of base:");
    int a,b;
    scanf("%d%d",&a,&b);
    int h;
    printf("Enter the value of height:");
    scanf("%d",&h);
    double area=((a+b)*h)/2.0;
    printf("Area of the Trapezoid = %0.2lf\n",area);
}

Input/Output:
Enter the value of base:5
7
Enter the value of height:8
Area of the Trapezoid = 48.00

Program in C++

Here is the source code of the C++ Program to compute the area of the Trapezoid.

Code:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
   cout<<"Enter the value of base:";
    int a,b;
    cin>>a;
    cin>>b;
    int h;
    cout<<"Enter the value of height:";
    cin>>h;
    double area=((a+b)*h)/2.0;
    cout<<"Area of the Trapezoid = "<<area;
}

Input/Output:
Enter the value of base:4
9
Enter the value of height:10
Area of the Trapezoid = 65

Program in Java
  
Here is the source code of the Java Program to compute the area of the Trapezoid.

Code:

import java.util.Scanner;
public class Area_Trapezoid {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the value of base:");
    int a=cs.nextInt();
    int b=cs.nextInt();
    int h;
    System.out.println("Enter the value of height:");
    h=cs.nextInt();
    double area=((a+b)*h)/2.0;
    System.out.println("Area of the Trapezoid = "+area);
    cs.close();
}
}

Input/Output:
Enter the value of base:
11
13
Enter the value of height:
24
Area of the Trapezoid = 288.0


Program in Python
  
Here is the source code of the Python Program to compute the area of the Trapezoid.

Code:

print("Enter the value of base:")
a=int(input())
b=int(input())
h=int(input("Enter the value of height:"))
area=((a+b)*h)/2.0
print("Area of the Trapezoid = ",area)

Input/Output:

Post a Comment

0 Comments