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. Point p;
  10. scanf("%lf %lf", &p.x, &p.y);
  11. return p;
  12. }
  13.  
  14. double area_of(Point p1, Point p2){
  15. double yoko = fabs(p2.x-p1.x);
  16. double tate = fabs(p2.y-p1.y);
  17. return yoko*tate;
  18. }
  19. double circumference_of(Point p1, Point p2){
  20. double yoko = fabs(p2.x-p1.x);
  21. double tate = fabs(p2.y-p1.y);
  22. return 2.0*(yoko+tate);
  23. }
  24. int main(void) {
  25.  
  26. Point p1 = scan_point();
  27. Point p2 = scan_point();
  28. printf("座標1 (%.2f, %.2f)",p1.x,p1.y);
  29. printf("\n座標2 (%.2f, %.2f)",p2.x,p2.y);
  30. printf("\n面積:%.2f",area_of(p1,p2));
  31. printf("\n周囲の長さ:%.2f",circumference_of(p1,p2));
  32. circumference_of(p1, p2);
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5324KB
stdin
5 6 7 8 
stdout
座標1 (5.00, 6.00)
座標2 (7.00, 8.00)
面積:4.00
周囲の長さ:8.00