Saturday, August 18, 2018

THREE IDIOTS

  • Problem Description

    Ajay, Binoy and Chandru were very close friends at school. They were very good in Mathematics and they were the pet students of Emily Mam. Their gang was known as 3-idiots. Ajay, Binoy and Chandru live in the same locality.
    A new student Dinesh joins their class and he wanted to be friends with them. He asked Binoy about his house address. Binoy wanted to test Dineshs mathematical skills. Binoy told Dinesh that his house is at the midpoint of the line joining Ajays house and Chandrus house. Dinesh was puzzled. Can you help Dinesh out?
    Given the coordinates of the 2 end points of a line (x1,y1) and (x2,y2), write a C program to find the midpoint of the line.
    Input Format:
    Input consists of 4 integers. The first integer corresponds to x1 . The second integer corresponds to y1. The third and fourth integers correspond to x2 and y2 respectively.
  • CODING ARENA::
  • #include <stdio.h>
    int main()
    {
      float a, b, c, d,e,f; 
      scanf("%f\t%f\n%f\t%f",&a, &b, &c, &d); 
      e=(a+c)/2;
      f=(b+d)/2;
      printf("Binoys house is located at(%.1f,%.1f)",e, f);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    2 4
    
    10 15
    
    
    Expected Output
    Binoys house is located at(6.0,9.5)
  • Test Case 2

    Input (stdin)
    106 20
    
    110 40
    
    
    Expected Output
    Binoys house is located at(108.0,30.0)

7 comments:

  1. can u give this program in PYTHON please

    ReplyDelete
    Replies
    1. x1 = float(input())
      y1 = float(input())
      x2 = float(input())
      y2 = float(input())
      a = ((x1+x2)/2.0)
      b = ((y1+y2)/2.0)
      print("Binoy's house is located at ""("+str(a)+","+str(b)+")")

      Delete
    2. print statement also write as
      print("Binoy's house is located at (%0.1f,%0.1f)"%(a,b))

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. How we will do it in java , in the last printing statement.

    ReplyDelete