C Program To Find Area Of Triangle

C Program To Find Area Of Triangle

C program to find the area of a triangle; Through this tutorial, we will learn how to find the area of triangle formula, function, and pointer in c programs.

Programs and Algorithm To Find Area Of Triangle

Use the following algorithm and program to find/calculate area of triangle formula, function, and pointer in c:

  • Algorithm To Find Area Of Triangle
  • C Program To Find Area Of Triangle using Formula
  • C Program To Find Area Of Triangle using Function
  • C Program To Find Area Of Triangle using Pointer

Algorithm To Find Area Of Triangle

Use the following algorithm to write a program to find area of triangle; as follows:

  • Start
  • Take input height and width from user and store it into variables.
  • Calculate area of triangle = area=(base*height)/2;
  • print “Area of Triangle=”, area
  • End

C Program To Find Area Of Triangle using Formula

#include<stdio.h>
int main()
{
	float base,height,area;
	printf("enter base of triangle: ");
	scanf("%f",&base);
	
	printf("enter height of the triangle: ");
	scanf("%f",&height);
	area=(base*height)/2;
	printf("Area Of Triangle is: %f\n",area);
	return 0;
}

The output of the above c program; as follows:

enter base of triangle: 10
enter height of the triangle: 25
Area Of Triangle is: 125.000000

C Program To Find Area Of Triangle using Function

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

The output of the above c program; as follows:

enter base of triangle: 12
enter height of the triangle: 15
Area Of Triangle: 90.000000

C Program To Find Area Of Triangle using Pointer

#include<stdio.h>
void area(float *b,float *h,float *area)
{
	*area=((*b)*(*h))/2;
}
 
int main()
{
	
 
	float b,h,a;
	printf("enter base of triangle: ");
	scanf("%f",&b);
	
	printf("enter height of the triangle: ");
	scanf("%f",&h);
	area(&b,&h,&a);
	printf("Area Of Triangle: %f\n",a);
	return 0;
}

The output of the above c program; as follows:

enter base of triangle: 10
enter height of the triangle: 12
Area Of Triangle: 60.000000

Recommended C Programs

AuthorAdmin

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 *