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(void) {
  10. Point p;
  11. scanf("%lf %lf", &p.x, &p.y);
  12. return p;
  13. }
  14.  
  15. double area_of(Point p1, Point p2) {
  16. return fabs(p2.x - p1.x) * fabs(p2.y - p1.y);
  17. }
  18.  
  19. double circumference_of(Point p1, Point p2) {
  20. return 2 * (fabs(p2.x - p1.x) + fabs(p2.y - p1.y));
  21. }
  22.  
  23. int main(void) {
  24. Point p1, p2;
  25. printf("左上の座標を入力してください(例: 1 1): ");
  26. p1 = scan_point();
  27. printf("右下の座標を入力してください(例: 4 5): ");
  28. p2 = scan_point();
  29.  
  30. printf("面積\t%.2f\n", area_of(p1, p2));
  31. printf("周囲の長さ\t%.2f\n", circumference_of(p1, p2));
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5284KB
stdin
0 0
10 10
stdout
左上の座標を入力してください(例: 1 1): 右下の座標を入力してください(例: 4 5): 面積	100.00
周囲の長さ	40.00