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. {
  15. printf("座標1を入力してください:");
  16. point p1=scan_point();
  17. printf("座標1(%.2f,%.2f)\n",p1.x, p1.y );
  18.  
  19. printf("座標2を入力してください:");
  20. point p2=scan_point();
  21. printf("座標2(%.2f,%.2f)\n",p2.x, p2.y );
  22.  
  23. printf("面積:%.2f\n", area_of(p1, p2));
  24. printf("周囲の長さ:%.2f\n", circumference_of(p1, p2));
  25.  
  26. return 0;
  27. }
  28. point scan_point(void){
  29. point p;
  30. scanf("%lf", &p.x);
  31. scanf("%lf", &p.y);
  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 * (width + height);
  45. }
  46.  
  47.  
  48.  
Success #stdin #stdout 0.01s 5288KB
stdin
1 
4
5
2
stdout
座標1を入力してください:座標1(1.00,4.00)
座標2を入力してください:座標2(5.00,2.00)
面積:8.00
周囲の長さ:12.00