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