fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. /* 三角形の構造体 */
  5. struct Triangle {
  6. double a;
  7. double b;
  8. double c;
  9. };
  10.  
  11. int main(void) {
  12. struct Triangle t;
  13. double p, s;
  14.  
  15. /* 辺の長さを固定 */
  16. t.a = 5;
  17. t.b = 5;
  18. t.c = 5;
  19.  
  20. p = (t.a + t.b + t.c) / 2.0;
  21.  
  22. s = sqrt(p * (p - t.a) * (p - t.b) * (p - t.c));
  23.  
  24. printf("a:%d\n", (int)t.a);
  25. printf("b:%d\n", (int)t.b);
  26. printf("c:%d\n", (int)t.c);
  27. printf("三角形の面積:%f\n", s);
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
a:5
b:5
c:5
三角形の面積:10.825318