Saturday, August 17, 2013

Given a Charecter C and an integer N. Repeat the character C N times using Recursion

#include <iostream>
using namespace std;

void repeat_char(char c, int n){
    if(n == 0) return;
    cout<<c;
    repeat_char(c, n-1);
}

int main()
{
    int n;
    char c;
    while(cin>>c>>n){
        repeat_char(c, n);
    }
    return 0;
}

No comments:

Post a Comment