recursion
int function(int value) {
if(value < 1)
return;
function(value - 1);
printf("%d ",value);
}
recursion
int function(int value) {
if(value < 1)
return;
function(value - 1);
printf("%d ",value);
}
recursion
# modified code tranclated to python from (Drab Duck)
def fact(num):
if num <= 1:
return 1
else:
return num*fact(num-1)
recursion
/*Java*/
static void recursion(){ recursion(0); }
static void recursion(int x){
System.out.println("eheh " + x);
if(x != 666) recursion(x+1);
}
recursion
function loop(x) {
if (x >= 10) // "x >= 10" is the exit condition (equivalent to "!(x < 10)")
return;
// do stuff
loop(x + 1); // the recursive call
}
loop(0);
recursion
def is_divisible(x, y):
if x % y == 0:
return True
else:
return False
def is_power(a, b):
if a == 1 or b == 1: # a more succinct way to test base case
return a == 1
return is_divisible(a, b) and is_power(a/b, b) # divisible and recursions report True?
Recursion
/**
* Return all subsequences of word (as defined above) separated by commas,
* with partialSubsequence prepended to each one.
*/
private static String subsequencesAfter(String partialSubsequence, String word) {
if (word.isEmpty()) {
// base case
return partialSubsequence;
} else {
// recursive step
return subsequencesAfter(partialSubsequence, word.substring(1))
+ ","
+ subsequencesAfter(partialSubsequence + word.charAt(0), word.substring(1));
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us