INSIDE_OUT

Problem statement
Contest source

Author , Tester , Editorialist : Jashwanth

DIFFICULTY:

easy

PREREQUISITES:

11th 12th mathematics

PROBLEM:

we were being asked to find whether the given point is inside the given circle or outside the given circle , given the constraints that , the circle has its center at (c,0) and passes through origin

EXPLANATION:

as the circle has its center at (c,0) and passes through the center , we can say that its radius is c.

meaning:

  • the equation
    x^2 + y^2 -2xc =0
  • gives zero for any point on the circle
  • gives positive number if coordinates (x,y) lie outside the circle
  • give negative number if coordinates (x,y) lie inside the circle

SOLUTION :

#include<time.h>
#include<math.h>
#include<stream>
#include<vector>
#include<stdlib.h>
#include<iostream>
using namespace std;


int inside_outside(int c,int x, int y)
{
float result = pow(x,2)+pow(y,2)-2*x*c;
if(result >0)
    return 1;
else if(result<0)
    return -1;
else    
    return 0;    
}

int main() {
int c,x,y;
cin>>c>>x>>y;
cout<<inside_outside(c,x,y);
return 0;
}