Sunday 26 July 2015

C Program to calculate the area of triangle using the formula area = ( s (s-a) (s-b)(s-c))1/2 where s= (a+b+c)/2

An Area of Triangle can be calculated so many ways. But the basic formula to find the area of triangle is

area = ( s (s-a) (s-b)(s-c))1/2 where s= (a+b+c)/2

The following Triangle show how these values are represented on  Triangle

Where is the Semi-Parameter and it can be calculated as s = a+b+c/2 . Where a, b, c are the lengths of AB, BC, CD edges respectively. The following C program calculates the area of triangle when their lengths a, b, c are given.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()

{
int a, b, c;
float s,Area;
a=b=c=s=0;
clrscr();
printf(" welcome to www.tutorialTpont.net\n");
printf("enter values of a, b, c\n");
scanf("%d %d %d", &a,&b,&c);


s=(a+b+c)/2;
Area = sqrt(s*(s-a)*(s-b)*(s-c));
printf(" Area of Triangle = %f\n " , Area);
getch();
} 
In the above program we are first inputting the values of a, b, c at line number 11 & 12. Then we calculating the value of s and the area of the triangle using the formal given in the problem. Finally I am printing the values of area using the printf statement at line number 15. It gives the following output when it successfully executed.



Finlay we got the area of triangle as shown above. If you have any doubts ask below.

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top