Saturday, August 18, 2018

IO 4


  • Problem Description

    Given two cities at geographic coordinates (xA,yA) and (xB,yB), and calculate the distance between from city A to city B?

    Note: Use the distance between points formula

    dist=sqrt(pow((x2-x1),2)+pow((y2-y1),2))

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.
  • CODING ARENA
  • #include <stdio.h>
    #include<math.h>
    int main()
    {
      int x1,x2,y1,y2;
      float r;
      scanf("%d%d",&x1,&y1);
      scanf("%d%d",&x2,&y2);
      r=sqrt(pow((x2-x1),2)+pow((y2-y1),2))
      printf("The distance between two points is=%.3f units",r);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    12 33
    
    13 4
    
    
    Expected Output
    The distance between two points is=29.02 units
  • Test Case 2

    Input (stdin)
    7 6
    
    2 3
    
    
    Expected Output
    The distance between two points is=5.83 units

No comments:

Post a Comment