fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. typedef struct {
  6. double x;
  7. double y;
  8. } Point;
  9.  
  10. Point scan_point(void);
  11. double area_of(Point p1, Point p2);
  12. double circumference_of(Point p1, Point p2);
  13.  
  14. int main(void) {
  15. Point p1 = scan_point();
  16. Point p2 = scan_point();
  17. double area = area_of(p1, p2);
  18. double circ = circumference_of(p1, p2);
  19. printf("座標1 (%.2f, %.2f)\n", p1.x, p1.y);
  20. printf("座標2 (%.2f, %.2f)\n", p2.x, p2.y);
  21. printf("面積: %.2f\n", area);
  22. printf("周囲の長さ: %.2f\n", circ);
  23.  
  24. return 0;
  25. }
  26.  
  27. Point scan_point(void) {
  28. Point p;
  29. if (scanf("%lf %lf", &p.x, &p.y) != 2) {
  30. p.x = p.y = 0.0;
  31. }
  32. return p;
  33. }
  34.  
  35. double area_of(Point p1, Point p2) {
  36. double width = fabs(p2.x - p1.x);
  37. double height = fabs(p2.y - p1.y);
  38. return width * height;
  39. }
  40.  
  41. double circumference_of(Point p1, Point p2) {
  42. double width = fabs(p2.x - p1.x);
  43. double height = fabs(p2.y - p1.y);
  44. return 2.0 * (width + height);
  45. }
  46.  
Success #stdin #stdout 0.01s 5320KB
stdin
1 1
stdout
座標1 (1.00, 1.00)
座標2 (0.00, 0.00)
面積: 1.00
周囲の長さ: 4.00