Find Angle MBC Discussion Hackerrank Solution

 is a right triangle,  at .
Therefore, .

Point  is the midpoint of hypotenuse .

You are given the lengths  and .
Your task is to find  (angle , as shown in the figure) in degrees.

Input Format

The first line contains the length of side .
The second line contains the length of side .

Constraints


  • Lengths  and  are natural numbers.

Output Format

Output  in degrees.

Note: Round the angle to the nearest integer.

Examples:
If angle is 56.5000001°, then output 57°.
If angle is 56.5000000°, then output 57°.
If angle is 56.4999999°, then output 56°.

Sample Input

10
10

Sample Output

45°



## Three  Solutions:-- 

## Only This(Number -1) Solution Is Working In Hackerrank.

Solution :- 1

import math
AB=int(input())
BC=int(input())
#print(AB)
#print(BC)

# In Right Triangles: Median to the Hypotenuse is Equal to Half the Hypotenuse.

print(round(math.degrees(math.atan(AB/BC))),chr(176),sep="")






from math import *

ab = float(input())
bc = float(input())
print(str(int(round(degrees(atan(ab/bc)),0)))+'°')


import math
AB,BC=int(input()),int(input())
hype=math.hypot(AB,BC)                      #to calculate hypotenuse
res=round(math.degrees(math.acos(BC/hype))) #to calculate required angle 
degree=chr(176)                                #for DEGREE symbol
print(res,degree, sep='')

import math AB = int(raw_input()) BC = int(raw_input()) print str(int(round(math.degrees(math.atan2(AB,BC)))))+'°'

atan2 is a function of atan that accepts two inputs. From wikipedia:

The purpose of using two arguments instead of one is to gather 
information on the signs of the inputs in order to return the appropriate quadrant of the computed angle, which is not possible for the single-argument arctangent function. It also avoids the problems of division by zero.

The most important thing is that atan2(X,Y) can avoid the inaccuracy which is generated by X/Y if you use atan(X/Y).

That's the point of this problem.


Comments

Popular posts from this blog

XAMPP, SQL BASIC COMMANDS

The Minion Game Hackerrank Solution

Arrays - DS | HackerRank Solutions