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. t.a=5;
  16. t.b=5;
  17. t.c=5;
  18.  
  19. // ヘロンの公式の計算
  20. p = (t.a+t.b+t.c)/2.0;
  21.  
  22. // 2. 面積(S)の算出
  23. s = sqrt(p*(p-t.a)*(p-t.b)*(p-t.c));
  24.  
  25. // 結果の出力
  26. printf("a:5\n");
  27. printf("b:5\n");
  28. printf("c:5\n");
  29. printf("三角形の面積:%f\n",s);
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
a:5
b:5
c:5
三角形の面積:10.825318