Saturday 29 July 2017

Radius of a Circle

QUESTION DESCRIPTION

Madhan is handling mathematics to 8th grade. He taught area and perimeter of geometric shapes to his students. He thought to give a test based on triangle and circles.The task is to calculate radius of the circle that is inscribed in triangle given the three sides of the triangle. He has set 20 questions and he is tired of preparing answer keys.Write a program to find the radius of the circle inscribed in a triangle.

Input and Output Format :
Input consists of three integers a, b and c. The three integer
corresponds to three sides of a triangle.

TEST CASE 1


INPUT

3 4 5

OUTPUT

The radius of the circle is=1.00


EXPLANATION :

The code requires you to output the radius of a circle inscribed inside a triangle.
The input given is the three sides of the triangle and the output required is the radius of the circle that is inscribed inside the triangle in the specified format.

There are two basic geometric formula that can be used to get the desired result :
> r^2=(s-a)*(s-b)*(s-c)/s
> where s=(a+b+c)/2

The other method is  another format of the same formula that has been used above :

> r=((a+b-c)*(a+c-b)*(b+c-a))/2

ALGORITHM :
  • Accept the inputs in the program (int a,b,c)
  • Using either of the formulas calculate the value of the radius 
    • To calculate the square root of the equation the sqrt function is used, the header <math.h> needs to be imported to use the sqrt function.
  •  Print the radius with the desired tag "The radius of the circle is="

SOLUTION : (Please use this as reference only)

CODE