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

  • 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

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 *