fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct {
  5. double a;
  6. double b;
  7. double c;
  8. } Triangle;
  9.  
  10. double calculate_area(Triangle t) {
  11. double a=t.a;
  12. double b=t.b;
  13. double c=t.c;
  14.  
  15. double s = (a +b + c) / 2.0;
  16. return sqrt(s * (s - a) * (s - b) * (s - c));
  17. }
  18.  
  19. int main(void) {
  20. Triangle triangle;
  21. double area;
  22.  
  23. scanf("%lf", &triangle.a);
  24. scanf("%lf", &triangle.b);
  25. scanf("%lf", &triangle.c);
  26.  
  27. area = calculate_area(triangle);
  28.  
  29. printf("a:%.0f\n", triangle.a);
  30. printf("b:%.0f\n", triangle.b);
  31. printf("c:%.0f\n", triangle.c);
  32. printf("三角形の面積:%.6lf\n", area);
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5296KB
stdin
5
5
5
stdout
a:5
b:5
c:5
三角形の面積:10.825318