68.9k views
1 vote
Write a recursive, int -valued function, len, that accepts a string and returns the number of characters in the string .

User Nickhil
by
8.3k points

1 Answer

3 votes
Without knowing the language, it's pretty imposible to write it. Once you start thinking recursively, it's not a difficult problem.

While you're recursing, pass the string without the first character.
The base case would be a null string which would return 0.
The unwind would just add one and return that.
User Asafm
by
8.3k points