Check if given point lies in range of any of the given towers | C ++ program to implement the above approach ; Function to check if the point ( X , Y ) exists in the towers network - range or not ; Traverse the array arr [ ] ; Stores distance of the point ( X , Y ) from i - th tower ; If dist lies within the range of the i - th tower ; If the point ( X , Y ) does not lie in the range of any of the towers ; Driver Code ; If point ( X , Y ) lies in the range of any of the towers ; Otherwise
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkPointRange ( int arr [ ] [ 3 ] , int X , int Y , int N ) { for ( int i = 0 ; i < N ; i ++ ) { double dist = sqrt ( ( arr [ i ] [ 0 ] - X ) * ( arr [ i ] [ 0 ] - X ) + ( arr [ i ] [ 1 ] - Y ) * ( arr [ i ] [ 1 ] - Y ) ) ; if ( dist <= arr [ i ] [ 2 ] ) { return true ; } } return false ; } int main ( ) { int arr [ ] [ 3 ] = { { 1 , 1 , 3 } , { 10 , 10 , 3 } , { 15 , 15 , 15 } } ; int X = 5 , Y = 5 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( checkPointRange ( arr , X , Y , N ) ) { cout << " True " ; } else { cout << " False " ; } }