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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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