C Program to find Area of a Trapezoid

C Program to find Area of a Trapezoid

C program to find area of a trapezoid; Through this tutorial, we will learn how to find or calculate area of a trapezoid using standard formula, function and pointer in c programs.

Programs and Algorithm to Find Area of a Trapezoid

Use the following algorithm and programs to find or calculate area of a trapezoid using standard formula, function and pointer in c:

  • 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

Use the following 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 output 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 output 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 output of the above c program; as follows:

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

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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