fork download
  1.  
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. /* 三角形の3辺を表す構造体 */
  6. struct Triangle {
  7. double a;
  8. double b;
  9. double c;
  10. };
  11.  
  12. int main(void){
  13. struct Triangle t;
  14. double p;
  15. double s;
  16.  
  17. /* 入力 */
  18.  
  19. scanf("%lf %lf %lf", &t.a, &t.b, &t.c);
  20.  
  21. /* 半周長 */
  22. p = (t.a + t.b + t.c) / 2.0;
  23.  
  24. /* ヘロンの公式(sqrt を使用) */
  25. s = sqrt(p * (p - t.a) * (p - t.b) * (p - t.c));
  26.  
  27. /* 出力 */
  28. printf("a = %.2f, b = %.2f, c = %.2f\n", t.a, t.b, t.c);
  29. printf("面積 s = %.6f\n", s);
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.01s 5316KB
stdin
5 5 5
stdout
a = 5.00, b = 5.00, c = 5.00
面積 s = 10.825318