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