fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct{
  4. double x;
  5. double y;
  6. }Point;
  7.  
  8. Point scan_point(void){
  9. Point p;
  10.  
  11. scanf("%lf %lf", &p.x, &p.y);
  12.  
  13. return p;
  14. }
  15.  
  16. double area_of(Point p1, Point p2){
  17. double S;
  18. S=(p1.x-p2.x)*(p1.y-p2.y);
  19. if(S<0){
  20. S=S*(-1);
  21. }
  22. return S;
  23. }
  24.  
  25. double circumference_of(Point p1, Point p2){
  26. double L, x, y;
  27. x=p1.x-p2.x;
  28. y=p1.y-p2.y;
  29. if(x<0){
  30. x=x*(-1);
  31. }
  32. if(y<0){
  33. y=y*(-1);
  34. }
  35. L=x*2+y*2;
  36. return L;
  37. }
  38.  
  39.  
  40. int main (void){
  41. Point p1, p2;
  42.  
  43. printf("左上隅の座標を入力してください。\n");
  44. p1=scan_point();
  45.  
  46. printf("右上隅の座標を入力してください。\n");
  47. p2=scan_point();
  48.  
  49. printf("座標1(%.2f, %.2f)\n", p1.x, p1.y);
  50. printf("座標2(%.2f, %.2f)\n", p2.x, p2.y);
  51.  
  52. printf("面積:%.2f\n", area_of(p1, p2));
  53. printf("周囲の長さ:%.2f\n", circumference_of(p1, p2));
  54.  
  55. return 0;
  56. }
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