need help with recursive function

Sorry.. I'm an Italian boy so my English couldn't be very perfect.

This problem can be solved by "recursive thinking" because it can be showed

as:

function chars_of_number(n: word): byte;

begin

if n<10 then chars_of_number:=1 else

chars_of_number:=1+chars_of_number(n div 10);

end;

so the function becomes a recursive-one. The teacher cauld have assigned it

to force the student to think in recursive mode and teach him to apply this

method every time he likes...

I'm sorry for showing an example in pascal code, but it was the only method

to tell my idea about teacher's assignment.

Jud McCranie ha scritto nel messaggio ...

Quote:

>>This is probably a school assignment, and is probably designed to teach

"recursive

>>thinking" (or what mathematicians call "induction"). Now, once one knows

how to

>>solve a (recursive) problem recursively, one can also learn when to use

iteration,

>>or other techniques.

>But it is bad uses of recursion like this that give people the

>wrong idea, because it is much better done iteratively. And

>iteration should come before recursion.

>Jud McCranie