思路:如果在函數(shù)體重不能使用變量,同時(shí)考慮到斐波那契數(shù)列的遞歸求解的過(guò)程,可以聯(lián)想到使用“遞歸”來(lái)實(shí)現(xiàn)。
實(shí)現(xiàn)代碼:
#include <stdio.h>
#include <stdlib.h>
// strlen實(shí)現(xiàn),但是在其中不能使用任何變量
int myStrlen(char* str)
{
if ('\0' == *str)
{
return 0;
}
else
{
return (1 + myStrlen(str + 1));
}
}
int main()
{
char* str = "hello world";
printf("%d\n", myStrlen(str));
return 0;
}