开发者

Display matrix with alternate 0 and 1 for each inner matrix

What will be algo for print a matrix of the order n(given as input by user) and always odd number.

Example: In user give n = 7 Output will be

1 1 开发者_如何学Go1 1 1 1 1

1 0 0 0 0 0 1

1 0 1 1 1 0 1

1 0 1 0 1 0 1

1 0 1 1 1 0 1

1 0 0 0 0 0 1

1 1 1 1 1 1 1


Consider we want to print point (x, y) (the center is (0, 0)). Take max(abs(x), abs(y)) and look if it is odd or even and print 0 for even and 1 for odd.

You should iterate from y = n / 2 to y = - n / 2 and the trough x = - n / 2 to x = n / 2

Sorry for my poor English

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜