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 Point_scan(void){
  10. Point a1;
  11. scanf("%lf",&a1.x);
  12. scanf("%lf",&a1.y);
  13. return a1;
  14. }
  15.  
  16. double area_of(Point p1,Point p2){
  17. return fabs(p1.x-p2.x)*fabs(p1.y-p2.y);
  18. }
  19.  
  20. double circumference_of(Point p1, Point p2){
  21. return fabs(p1.x-p2.x)*2+fabs(p1.y-p2.y)*2;
  22. }
  23.  
  24. int main(void) {
  25. printf("左上隅と右下隅の座標を入力してください。\n");
  26. Point p1=Point_scan();
  27. printf("座標1(%.2f,%.2f)\n",p1.x,p1.y);
  28. Point p2=Point_scan();
  29. printf("座標2(%.2f,%.2f)\n",p2.x,p2.y);
  30.  
  31. printf("面積:%.2f\n",area_of(p1,p2));
  32. printf("周囲の長さ:%.2f\n",circumference_of(p1, p2));
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5284KB
stdin
1
1
4
6
stdout
左上隅と右下隅の座標を入力してください。
座標1(1.00,1.00)
座標2(4.00,6.00)
面積:15.00
周囲の長さ:16.00