fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. struct Triangle {
  5. double a;
  6. double b;
  7. double c;
  8. };
  9.  
  10. int main(void) {
  11. struct Triangle t;
  12. double s, area;
  13.  
  14. // --- 入力部分 ---
  15. printf("a : ");
  16. scanf("%lf", &t.a);
  17. printf("b : ");
  18. scanf("%lf", &t.b);
  19. printf("c : ");
  20. scanf("%lf", &t.c);
  21.  
  22. // ※ もし「特定の値を代入したい」場合は、scanfを使わずに以下のように書きます
  23. // t.a = 6; t.b = 6; t.c = 6; (末尾にセミコロンが必要)
  24.  
  25. // --- 計算部分 ---
  26. s = (t.a + t.b + t.c) / 2.0;
  27. area = sqrt(s * (s - t.a) * (s - t.b) * (s - t.c));
  28.  
  29. // --- 出力部分 ---
  30. // 出力結果の例に合わせて、a, b, c の後ろはコロン「:」にしています
  31. printf("a : %.0.lf\n", t.a);
  32. printf("b : %.0.lf\n", t.b);
  33. printf("c : %.0.lf\n", t.c);
  34. printf("三角形の面積 : %lf\n", area);
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
a : b : c : a : %.0.lf
b : %.0.lf
c : %.0.lf
三角形の面積 : 0.000000