How to create a checkerboard using fprintf?

I already have the code for the checkerboard. The problem is that the order of the symbols are not correct.
for a=1:10
for b=1:5
fprintf('X')
fprintf('O')
end
fprintf('\n')
end
I want it so the first row ends with O and the second row ends with X. Can you please help me on this with a simple solution that does not take a lot of lines.

 採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 16 日

0 投票

Add another for b loop that prints in the other order.

4 件のコメント

Rafael
Rafael 2017 年 11 月 16 日
I tried that, it only returns the same pattern next to the old one with the same order.
Walter Roberson
Walter Roberson 2017 年 11 月 16 日
for a=1:10
for b=1:5
fprintf('X')
fprintf('O')
end
fprintf('\n')
for b=1:5
fprintf('O')
fprintf('X')
end
fprintf('\n')
end
Rafael
Rafael 2017 年 11 月 16 日
Nice, thank you.
Walter Roberson
Walter Roberson 2017 年 11 月 16 日
You see, it was exactly what I said: adding another for b loop that printed in the other order.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by