C Program to find Area of a Trapezoid

In this tutorial, i am going to show you how to find or calculate area of a trapezoid with the help of standard formula, function and pointer in c programs.

All C Programs and Algorithm to Find Area of a Trapezoid

  • Algorithm to Find Area of a Trapezoid
  • C Program to Find Area of a Trapezoid using Formula
  • C Program to Find Area of a Trapezoid using Function
  • C Program to Find Area of a Trapezoid using Pointer

Algorithm to Find Area of a Trapezoid

Just follow the below given algorithm to write a program to find the area of a trapezoid; as follows:

  1. Take input 2 base and height of Trapezoid. Store it in 3 different variables.
  2. Calculate area of trapezoid using area=((base1+base2)/2 )*height;
  3. Finally, print the value of area of Trapezoid.

C Program to Find Area of a Trapezoid using Formula

#include<stdio.h>
int main()
{
	float base1,base2,height,area;
	printf("enter base1 of parallelogram: ");
	scanf("%f",&base1);
	printf("enter base2 of parallelogram: ");
	scanf("%f",&base2);
	printf("enter height of the parallelogram: ");
	scanf("%f",&height);
	area=((base1+base2)/2 )*height;
	printf("Area of Trapezoid: %f\n",area);
	return 0;
}

The result of the above c program; as follows:

enter base1 of parallelogram: 8
enter base2 of parallelogram: 4
enter height of the parallelogram: 2
Area of Trapezoid: 12.000000

C Program to Find Area of a Trapezoid using Function

#include<stdio.h>
float area(float a,float b,float h)
{
	return ( ((a+b)/2) * h);
}
 
int main()
{
	float b,h,a,A;
	printf("enter a: ");
	scanf("%f",&a);
	
	printf("enter b: ");
	scanf("%f",&b);
	
	printf("enter h: ");
	scanf("%f",&h);
	A=area(a,b,h);
	printf("Area of Trapezoid : %f\n",A);
	return 0;
}

The result of the above c program; as follows:

enter a: 8
enter b: 8
enter h: 6
Area of Trapezoid : 48.000000

C Program to Find Area of a Trapezoid using Pointer

#include<stdio.h>
void AOT(float *a,float *b,float *h,float *area)
{
	*area=((*a+*b)/2)*(*h);
}
 
int main()
{
	
 
	float b1,b2,h,area;
	printf("enter base1: ");
	scanf("%f",&b1);
	
	printf("enter base2: ");
	scanf("%f",&b2);
	
	printf("enter height: ");
	scanf("%f",&h);
	AOT(&b1,&b2,&h,&area);
	printf("Area of Trapezoid : %f\n",area);
	return 0;
}

The result of the above c program; as follows:

enter base1: 5
enter base2: 2
enter height: 6
Area of Trapezoid : 21.000000

More C Programming Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *