Number of Squares Python
PROGRAM TO FIND NUMBER OF SQUARES IN A RECTANGLE
OUTPUT
Count of Squares is 20
def countSquares(m, n): # If n is smaller, swap m and n if(n < m): temp = m m = n n = temp # Now n is greater dimension, # apply formula return n * (n + 1) * (3 * m - n + 1) // 6 # Driver Code if __name__=='__main__': m = 4 n = 3 print("Count of squares is", countSquares(m, n))
Count of Squares is 20
Comments
Post a Comment