J'ai fait ce qui suit pour calculer le logarithme récursif :(b est la base du log ici)
int log(int b, int n ) {
if (n/b ==1) {
return 1;
} else {
return log( b, n/b)+1 ;
}
}
Je le fais à partir de la plateforme interactive openDSA. La question originale est la suivante :
For function "log", write the missing base case condition and the recursive call. This function computes the log of "n" to the base "b". As an example: log 8 to the base 2 equals 3 since 8 = 2*2*2. We can find this by dividing 8 by 2 until we reach 1, and we count the number of divisions we made. You should assume that "n" is exactly "b" to some integer power.
1
int log(int b, int n ) {
2
if <<Missing base case condition>> {
3
return 1;
4
} else {
5
return <<Missing a Recursive case action>>
6
}
7
}
Mon code est incorrect. J'obtiens une récursion infinie.