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