Solved

# count squares of different dimensions in a matrix

Posted on 2007-10-11

I have a question. It isn't homework I just want to know the logic that must be applied in this program.

Suppose u r given a 4*3 rectangle like (take these values from user)

__________________________

| | | |

| | | |

|________|_________|________|

| | | |

| | | |

|________|_________|________|

| | | |

| | | |

|________|_________|________|

| | | |

| | | |

|________|_________|________|

Now calculate the no. of squares in this rectangle like:

No. of squares of dimension 1 is 12

No. of squares of dimension 2 is 6

No. of squares of dimension 3 is 2

No. of squares of dimension 4 is 0

Total no. of squares are 20.

So, can anyone please help me with the logic?

Thanks.