Saturday, August 17, 2013

Given a string. Find the String length using Recursion.

#include <iostream>
#include <cstdio>
using namespace std;
#define siz 100
char as[siz];
int find_length(char as[], int i){
    if(as[i]=='\0') return i;
    find_length(as,i+1);
}

int main()
{
    while(gets(as)){
        cout<<find_length(as,0)<<endl;
    }
    return 0;
}

No comments:

Post a Comment