Archive:Area of triangle using C: Difference between revisions
Appearance
wikademia>MichaelFrey mNo edit summary |
wikademia>Emesee m Area of Triangle moved to Area of triangle using C |
(No difference)
| |
Revision as of 22:51, 19 October 2008
<source lang="c">
- include<stdio.h>
- include<math.h>
/* main: calculate the area of a triangle using Heron's Formula */ int main(void) {
float a, b, c, s, area;
printf("Enter sides of triangle: ");
scanf("%f%f%f", &a, &b, &c);
s = (a + b + c) / 2;
/* no error checking: sqrt() works only if its arg >= 0 */
area = sqrt(s * (s-a) * (s-b) * (s-c));
printf("Area = %f\n", area);
/* indicate success */ return 0;
} </source>