#を表示する4

問題

##    ##    ##

    ##    ##    ##

##    ##    ##

    ##    ##    ##

##    ##    ##

    ##    ##    ##

 

 解答と過程

d•問題を考える

•繰り返しで行の内部の数がどう変わって行くのかを考える

•upRow関数を用いてデザインしてやる

 

*/

 

#include <iostream>

using namespace std;

 

void upRow(int repeatNum, char str);

void downRow(int repeatNum, char str);

 

 

int main(){

 

    for (int i = 1; i <= 3; i++) {

 

        for (int j = 1; j <= 3; j++) {

            upRow(2, '#');

            upRow(2, ' ');

        }

        

        cout << endl;

 

        for (int j = 1; j <= 3; j++) {

            upRow(2, ' ');

            upRow(2, '#');

        }

        cout << endl;

    }

}

 

void upRow(int repeatNum, char str) {

    for (int repeat = 1; repeat <= repeatNum; repeat++) {

        cout <<  str << flush;

    }

 

}

 

感想

前回横に文字を表示する関数を作っていたので、

今回はそれを並べるだけに集中して作りました。

多分最短で出来たんじゃないかな?

どうしても横と縦の出力の仕方が異なるのでそこの部分だけは

考えないといけませんね。