Determine the number of squares of unit area that a given line will pass through . |  ; Function to return the required position ; Driver Code
/ * C ++ program to determine the number of squares that line will pass through * #include < bits / stdc ++ . h > using namespace std ; int noOfSquares ( int x1 , int y1 , int x2 , int y2 ) { int dx = abs ( x2 - x1 ) ; int dy = abs ( y2 - y1 ) ; int ans = dx + dy - __gcd ( dx , dy ) ; cout << ans ; } int main ( ) { int x1 = 1 , y1 = 1 , x2 = 4 , y2 = 3 ; noOfSquares ( x1 , y1 , x2 , y2 ) ; return 0 ; }