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 = {0.00, 0.00};
  15. Point p2;
  16.  
  17. printf("左上隅と右下隅の座標を入力してください。\n");
  18. printf("座標1 (%.2f, %.2f)\n", p1.x, p1.y);
  19.  
  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. scanf("%lf %lf", &p.x, &p.y);
  34. printf("座標2 (%.2f, %.2f)\n", 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 0.01s 5320KB
stdin
1 1
stdout
左上隅と右下隅の座標を入力してください。
座標1 (0.00, 0.00)
座標2 (1.00, 1.00)
面積:1.00
周囲の長さ:4.00