誰でも私のコードを変更する方法を教えてもらえますか?このダイヤモンドコードのヘルプを依頼する
2つのループだけを使用してダイヤモンドパターンを印刷したいとします。私は5を入力した場合 、ダイヤモンドは次のようにする必要があります:
*
***
*****
***
*
私は半分の方法が行われています。
これは私がこれまでに得たものです。
#include <iostream>
using namespace std;
// print diamond. Instead of finding * pattern, just find " " 's pattern.
int main()
{
int size;
cin >> size;
int m = size/2;
for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) { // Before || is the left part. After || is right part
if ((row < m && (col < m - row || col > m + row)) || (row > m && col < row - m))
cout << " ";
else
cout << "*";
}
cout << endl;
}
return 0;
}
「stackoverflow C++ diamond loops」では、この同じ種類のものについて多くの既存の質問が見つかりました。たぶんそれらのいくつかはあなたに役立つでしょう。 – TheUndeadFish
[C中に菱形を作成したい]の複製があります(http://stackoverflow.com/questions/22332781/want-to-create-diamond-shape-using-while-in-c) –
ダイヤモンドは、行の偶数のように見える、6と言う? – alhadhrami