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