fork download
  1. #include <stdio.h>//第3問
  2. #include <math.h>
  3.  
  4. typedef struct{
  5. double x;
  6. double y;
  7. }Point;
  8.  
  9. Point scan_point();
  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. printf("左上隅と右下隅の座標を入力してください。\n");
  16.  
  17. p1=scan_point();
  18. printf("座標1(%.2f, %.2f)\n",p1.x,p1.y);
  19.  
  20. p2=scan_point();
  21. printf("座標2(%.2f, %.2f)\n",p2.x,p2.y);
  22.  
  23. double area = area_of(p1,p2);
  24. double circ = circumference_of(p1,p2);
  25.  
  26. printf("面積:%.2f\n",area);
  27. printf("周囲の長さ:%.2f\n",circ);
  28.  
  29. return 0;
  30. }
  31.  
  32. Point scan_point(){
  33. Point p;
  34. scanf("%lf",&p.x);
  35. scanf("%lf",&p.y);
  36. return p;
  37. }
  38.  
  39. double area_of(Point p1, Point p2){
  40. double xx=fabs(p2.x-p1.x);
  41. double yy=fabs(p2.y-p1.y);
  42. return xx*yy;
  43. }
  44.  
  45. double circumference_of(Point p1, Point p2){
  46. double xx=fabs(p2.x-p1.x);
  47. double yy=fabs(p2.y-p1.y);
  48. return (xx+yy)*2;
  49. }
Success #stdin #stdout 0s 5320KB
stdin
1 2 3 4
stdout
左上隅と右下隅の座標を入力してください。
座標1(1.00, 2.00)
座標2(3.00, 4.00)
面積:4.00
周囲の長さ:8.00