fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. typedef struct {
  4. double x;
  5. double y;
  6. } Point;
  7.  
  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. printf("左上隅と右下隅の座標を入力してください。\n");
  15. p1 = scan_point();
  16. p2 = scan_point();
  17. printf("座標1 : (%.2f, %.2f)\n", p1.x, p1.y);
  18. printf("座標2 : (%.2f, %.2f)\n", p2.x, p2.y);
  19. printf("面積 : %.2f\n", area_of(p1, p2));
  20. printf("周囲の長さ : %.2f\n", circumference_of(p1, p2));
  21.  
  22.  
  23. return 0;
  24. }
  25.  
  26.  
  27. Point scan_point(void) {
  28. Point temp;
  29. scanf("%lf %lf", &temp.x, &temp.y);
  30. return temp;
  31. }
  32.  
  33. double area_of(Point p1, Point p2){
  34. double yoko = fabs(p1.x - p2.x);
  35. double tate = fabs(p1.y - p2.y);
  36. return yoko * tate;
  37. }
  38.  
  39. double circumference_of(Point p1, Point p2) {
  40. double yoko = fabs(p1.x - p2.x);
  41. double tate = fabs(p1.y - p2.y);
  42. return 2.0 * (tate + yoko);
  43. }
Success #stdin #stdout 0.01s 5276KB
stdin
1.00 1.00
0.00 0.00
stdout
左上隅と右下隅の座標を入力してください。
座標1 : (1.00, 1.00)
座標2 : (0.00, 0.00)
面積 : 1.00
周囲の長さ : 4.00