Number of Integral Points between Two Points | C # code to find the number of integral points lying on the line joining the two given points ; Class to represent an Integral point on XY plane . ; Utility function to find GCD of two numbers GCD of a and b ; Finds the no . of Integral points between two given points . ; If line joining p and q is parallel to x axis , then count is difference of y values ; If line joining p and q is parallel to y axis , then count is difference of x values ; Driver code
using System ; class GFG { public class Point { public int x , y ; public Point ( int a , int b ) { this . x = a ; this . y = b ; } } ; static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static int getCount ( Point p , Point q ) { if ( p . x == q . x ) return Math . Abs ( p . y - q . y ) - 1 ; if ( p . y == q . y ) return Math . Abs ( p . x - q . x ) - 1 ; return gcd ( Math . Abs ( p . x - q . x ) , Math . Abs ( p . y - q . y ) ) - 1 ; } public static void Main ( String [ ] args ) { Point p = new Point ( 1 , 9 ) ; Point q = new Point ( 8 , 16 ) ; Console . WriteLine ( " The ▁ number ▁ of ▁ integral ▁ points ▁ between ▁ " + " ( " + p . x + " , ▁ " + p . y + " ) ▁ and ▁ ( " + q . x + " , ▁ " + q . y + " ) ▁ is ▁ " + getCount ( p , q ) ) ; } }