This is a C Program to calculate the area of a triangle.

This C Program calculates the area of a triangle given it’s three sides.

The formula or algorithm used is: Area = sqrt(s(s – a)(s – b)(s – c)), where s = (a + b + c) / 2 or perimeter / 2. and a, b & c are the sides of triangle.

Here is source code of the C program to calculate the area of a triangle. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/* * C program to find the area of a triangle, given three sides */ #include <stdio.h> #include <math.h> void main() { int s, a, b, c, area; printf("Enter the values of a, b and c \n"); scanf("%d %d %d", &a, &b, &c); /* compute s */ s = (a + b + c) / 2; area = sqrt(s * (s - a) * (s - b) * (s - c)); printf("Area of a triangle = %d \n", area); }

In this C program, library function defined in <math.h> header file is used to compute mathematical functions. We are reading the three sides of a triangle using ‘a’, ‘b’, ‘c’ integer variables. To find the area of a triangle, the following formula is used.

Area = sqrt (s * (s – a) * (s – b) * (s – c))

$ cc pgm1.c -lm $ a.out Enter the values of a, b and c 12 10 8 Area of a triangle = 39

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms