C Program To Find Area Of Triangle

In this tutorial, i am going to show you how to find the area of triangle formula, function, and pointer in c programs.

All C 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

Follow the below given algorithm to write a program to find area of triangle; as follows:

  • Start program
  • 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 program

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

More C Programming Tutorials

Be First to Comment

Leave a Reply

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