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