Wednesday 9 March 2016

THREE IDIOTS


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 Dinesh's mathematical skills. Binoy told Dinesh that his house is at the midpoint of the line joining Ajay's house and Chandru's 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 fouth integers correspond to x2 and y2 respectively. 

Output Format:
Refer Sample Input and Output for exact formatting specifications. [All floating point values are displayed correct to 1 decimal place] 

Sample Input and Output: 
[All text in bold corresponds to input and the rest corresponds to output] 
Enter x1
Enter y1 
Enter x2 
10 
Enter y2 
15 
Binoy's house is located at (6.0 , 9.5)

Code:
  #include<stdio.h>
int main(){
  char s='(';
  char ss=')';
  int x1,x2,y1,y2;
  float mid1,mid2;
  printf("Enter x1\n");
  scanf("%d",&x1);
  printf("Enter y1\n");
  scanf("%d",&y1);
  printf("Enter x2\n");
  scanf("%d",&x2);
  printf("Enter y2\n");
  scanf("%d",&y2);
  mid1=((x1+x2)/2.0);
  mid2=((y1+y2)/2.0);
  printf("Binoy's house is located at %c%.1f , %.1f%c",s,mid1 , mid2,ss);
  
  
  return 0;
}

5 comments:

  1. 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