fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double sanpen(double a, double b, double c) {
  5. double s = (a + b + c) / 2;
  6. double area = sqrt(s * (s - a) * (s - b) * (s - c));
  7. return area;
  8. }
  9.  
  10. int main() {
  11. double a, b, c;
  12.  
  13. printf("Enter the lengths of the three sides of the triangle (a, b, c): ");
  14. scanf("%lf %lf %lf", &a, &b, &c);
  15.  
  16. if (a + b > c && a + c > b && b + c > a) {
  17. double area = sanpen(a, b, c);
  18. printf("The area of the triangle is: %.2f\n", area);
  19. } else {
  20. printf("The given sides do not form a valid triangle.\n");
  21. }
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 5280KB
stdin
stdout
Enter the lengths of the three sides of the triangle (a, b, c): The area of the triangle is: 0.00