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