# write an algorithm to calculate the area of triangle using the formula sqrt(s(s-a)(s-b)(s-c))?

• write an algorithm to calculate the area of triangle using the formula sqrt(s(s-a)(s-b)(s-c))?

Answer #1 | 29/12 2013 00:00
Algorithm: INPUT a, b, c s = (a + b + c) / 2 area = sqrt(s(s-a)(s-b)(s-c)) PRINT area END A C program to do this: #include #include int main() { double a, b, c, s, area; // a, b, c can be input repeatedly without restarting program. Press ctrl+D (Linux) or ctrl+Z (Windoze) to end the program while (scanf("%lf %lf %lf", &a, &b, &c) == 3) { s = (a + b + c) / 2.0; area = sqrt(s * (s - a) * (s - b) * (s - c)); printf("%.2lf\n", area); } return(0); }
Answer #2 | 29/12 2013 00:08
1. Read three sides (a,b,c) 2. calculate s=(a+b+c)/2 3. calculate area=sqrt(s*(s-a)*(s-b)*(s-c)) 4.print area #include #include int main() { float a,b,c,s,area; printf("Enter three sides of a triangle\n"); scanf("%f%f%f",&a,&b,&c); s=(a+b+c)/2; area=sqrt(s*(s-a)*(s-b)*(s-c)); printf("Area=%f\n", area); return 0; }