Starter Tutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.
Home » Programming » C Programming » Programs » Others » C program to calculate the area of a triangle
Suryateja Pericherla Categories: Others. No Comments on C program to calculate the area of a triangle
Join Our Newsletter - Tips, Contests and Other Updates
Email
Name

In this article we will learn to implement a C program to calculate the area of a triangle. A C program is provided below to read the three sides of triangle and display the area of the triangle as output.

//C program to calculate the area of a triangle
//Formula: area = (s(s-a)(s-b)(s-c))1/2,  where s=(a+b+c)/2. This formula is Heron's formula
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
	float a, b, c, s, area;
	printf("Enter side a: ");
	scanf("%f", &a);
	printf("Enter side b: ");
	scanf("%f", &b);
	printf("Enter side c: ");
	scanf("%f", &c);
	s = (a+b+c)/2;
	area = sqrt(s*(s-a)*(s-b)*(s-c));
	printf("Area of the triangle is: %.3f", area);
	getch();
}

 

Input and output for the above program is as follows:

Enter side a: 5
Enter side b: 6
Enter side c: 8
Area of the triangle is: 14.981

 

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

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

Facebook
Twitter
Pinterest
Youtube
Instagram
Blogarama - Blog Directory