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