Answers for "recursive function"

1

bash vlookup function

# Example usage:
awk 'FNR==NR{a[$1]=$2; next}; {if($9 in a) {print $0, "\t"a[$9];} else {print $0, "\tNA"}}' input_file_1 input_file_2
# This command does a VLOOKUP-type operation between two files using
#	awk. With the numbers above, column 1 from input_file_1 is used 
#	an a key in an array with column 2 of input_file_1 as the match for 
#	the key. Column 9 of input_file_2 is then compared to the keys from
#	input_file_1 and any matches return the associated match from 
#	input_file_1 (here, column 2).
Posted by: Guest on October-01-2020
7

how to make recursive function in javascript

// Basic Recursive function
// It works in all languages but lets try with Javascript

// lets make a greedy factorial calculator

function my_recursive_factorial(nb) // nb to compute his factorial
{
  	if (nb < 0 || nb > 12) // error case
        return 0;
    if (nb == 1 || nb == 0)
        return 1; // you have to check limit for factorial
  
    return nb * my_recursive_factorial(nb - 1); // ! Recursive call !
}

//This will find factorial from 1 to 12 with recursive method

// Recursive functions are greedy and should be used in only special cases who need it
// or who can handle it.

// a function become recursive if she calls herself in stack
Posted by: Guest on August-09-2021
5

how to make recursive function

// Basic Recursive function
// It works in all languages but lets try with C

// lets make a greedy strlen

int my_recursive_strlen(int index, char *str) // note that index must be set at 0 to work in this case
{
  if (str[index] == '\0')
    return index + 1;
  else
    return my_recursive_strlen(index++); // i send index + 1 to next function call
  // this increment index in our recursive stack
}

void main(void)
{
  printf("length of Bonjour = %d\n", my_recursive_strlen(0, "bonjour"));
}

//output : length of Bonjour = 7

// Recursive functions are greedy and should be used in only special cases who need it
// or who can handle it.

// a function become recursive if she calls herself in stack
Posted by: Guest on August-09-2021
3

recursion

# modified code tranclated to python from (Drab Duck)

def fact(num):
  if num <= 1:
      return 1
  else:
    return num*fact(num-1)
Posted by: Guest on October-12-2020
0

recursive

private static long factorial(int n){  
	if (n == 1)
    	return 1;    
    else
		return n * factorial(n-1);
        }
Posted by: Guest on April-21-2021
-1

recursive function

tagnina
Posted by: Guest on August-26-2021

Code answers related to "recursive function"

Browse Popular Code Answers by Language