fork(1) 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. printf("辺 a を入力してください: ");
  17. scanf("%lf", &t.a);
  18.  
  19. printf("辺 b を入力してください: ");
  20. scanf("%lf", &t.b);
  21.  
  22. printf("辺 c を入力してください: ");
  23. scanf("%lf", &t.c);
  24.  
  25. /* ヘロンの公式 */
  26. p = (t.a + t.b + t.c) / 2.0;
  27. s = sqrt(p * (p - t.a) * (p - t.b) * (p - t.c));
  28.  
  29. /* 結果の出力 */
  30. printf("三角形の辺の長さ: a = %.2f, b = %.2f, c = %.2f\n", t.a, t.b, t.c);
  31. printf("三角形の面積: %.2f\n", s);
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
辺 a を入力してください: 辺 b を入力してください: 辺 c を入力してください: 三角形の辺の長さ: a = 0.00, b = 0.00, c = 0.00
三角形の面積: 0.00