Saturday, August 17, 2013

Make a block of characters using Recursion

#include <iostream>
#include <cstdio>
using namespace std;

void make_block(char c, int width, int height, int w){
    if(height == 0) return;
    else if(width == 0) {
        puts("");
        make_block(c, w, height-1, w);
    } else {
        cout<<c;
        make_block(c, width-1, height, w);
    }

}

int main()
{
    int width, height;
    char c;
    while(cin>>c>>width>>height){
        make_block(c, width, height, width);
    }
    return 0;
}

No comments:

Post a Comment