You are on page 1of 3

8/7/13

C program to find area of triangle | Programming Simplified

Home C programming C programming examples C program to find area of triangle

C program to find area of triangle

C program to find area of triangle: c programming code to calculate area of a triangle using Heron's or Hero's formula. User will enter the lengths of sides of triangle. Remember for a triangle to exist the sum of any two sides of a triangle must be greater than third side.

C programming code
/ *A s s u m i n gT r i a n g l ee x i s t s-v a l i di n p u tf r o mu s e r* / # i n c l u d e < s t d i o . h > # i n c l u d e < m a t h . h >
www.programmingsimplified.com/c/source-code/c-program-find-area-of-triangle 1/3

8/7/13

C program to find area of triangle | Programming Simplified

m a i n ( ) { d o u b l ea ,b ,c ,s ,a r e a ; p r i n t f ( " E n t e rt h es i d e so ft r i a n g l e \ n " ) ; s c a n f ( " % l f % l f % l f " , & a , & b , & c ) ; s=( a + b + c ) / 2 ; a r e a=s q r t ( s * ( s a ) * ( s b ) * ( s c ) ) ; p r i n t f ( " A r e ao ft r i a n g l e=% . 2 l f \ n " ,a r e a ) ; r e t u r n0 ; }

C program to find area of triangle using function


# i n c l u d e < s t d i o . h > # i n c l u d e < m a t h . h > d o u b l ea r e a _ o f _ t r i a n g l e ( d o u b l e ,d o u b l e ,d o u b l e ) ; m a i n ( ) { d o u b l ea ,b ,c ,a r e a ; p r i n t f ( " E n t e rt h es i d e so ft r i a n g l e \ n " ) ; s c a n f ( " % l f % l f % l f " , & a , & b , & c ) ; a r e a=a r e a _ o f _ t r i a n g l e ( a ,b ,c ) ; p r i n t f ( " A r e ao ft r i a n g l e=% . 2 l f \ n " ,a r e a ) ; r e t u r n0 ; } d o u b l ea r e a _ o f _ t r i a n g l e (d o u b l ea ,d o u b l eb ,d o u b l ec) { d o u b l es ,a r e a ; s=( a + b + c ) / 2 ; a r e a=s q r t ( s * ( s a ) * ( s b ) * ( s c ) ) ;
www.programmingsimplified.com/c/source-code/c-program-find-area-of-triangle 2/3

8/7/13

C program to find area of triangle | Programming Simplified

r e t u r na r e a ; }

www.programmingsimplified.com/c/source-code/c-program-find-area-of-triangle

3/3

You might also like