fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. typedef struct {
  5. double x;
  6. double y;
  7. } Point;
  8.  
  9. Point scan_point();
  10. double area_of(Point p1, Point p2);
  11. double circumference_of(Point p1, Point p2);
  12.  
  13. int main() {
  14. Point p1, p2;
  15. double area, circum;
  16.  
  17. printf("左上隅と右下隅の座標を入力してください。\n");
  18. printf("左上隅:");
  19. p1 = scan_point();
  20. printf("(%.2lf,",p1.x);
  21. printf("%.2lf)",p1.y);
  22. printf("右下隅:");
  23. p2 = scan_point();
  24. printf("(%.2lf,",p2.x);
  25. printf("%.2lf)",p2.y);
  26. area = area_of(p1, p2);
  27. circum = circumference_of(p1, p2);
  28.  
  29. printf("面積 = %.2f\n", area);
  30. printf("周囲の長さ = %.2f\n", circum);
  31.  
  32. return 0;
  33. }
  34.  
  35. Point scan_point() {
  36. Point p;
  37. scanf("%lf %lf", &p.x, &p.y);
  38. return p;
  39. }
  40.  
  41. double area_of(Point p1, Point p2) {
  42. double a= fabs(p2.x - p1.x);
  43. double b= fabs(p2.y - p1.y);
  44. return a* b;
  45. }
  46.  
  47. double circumference_of(Point p1, Point p2) {
  48. double a= fabs(p2.x - p1.x);
  49. double b= fabs(p2.y - p1.y);
  50. return 2 * (a+ b);
  51. }
Success #stdin #stdout 0.01s 5312KB
stdin
0 0 1 1
stdout
左上隅と右下隅の座標を入力してください。
左上隅:(0.00,0.00)右下隅:(1.00,1.00)面積 = 1.00
周囲の長さ = 4.00