Archive:Area of triangle using C: Difference between revisions
Appearance
wikademia>JWSchmidt category |
wikademia>Wikademia |
||
| (4 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
< | <source lang="c"> | ||
#include<stdio.h> | #include<stdio.h> | ||
#include<math.h> | #include<math.h> | ||
/* main: calculate the area of a triangle using Heron's Formula */ | |||
int main(void) | |||
{ | { | ||
float a,b,c,s,area; | float a, b, c, s, area; | ||
printf("Enter sides of triangle: "); | |||
printf(" | scanf("%f%f%f", &a, &b, &c); | ||
scanf("%f%f%f",&a,&b,&c); | s = (a + b + c) / 2; | ||
s=(a+b+c) /2; | |||
area=sqrt(s*(s-a)*(s-b)*(s-c)); | /* no error checking: sqrt() works only if its arg >= 0 */ | ||
printf(" | area = sqrt(s * (s-a) * (s-b) * (s-c)); | ||
printf("Area = %f\n", area); | |||
/* indicate success */ | |||
return 0; | |||
} | } | ||
</ | </source> | ||
[[Category:C source code examples]] | [[Category:C source code examples]] | ||
Latest revision as of 07:54, 12 June 2009
<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>