Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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] == '')
    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
", 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
Comment

recursive function

>>> def sum_digits(n):
        """Return the sum of the digits of positive integer n."""
        if n < 10:
            return n
        else:
            all_but_last, last = n // 10, n % 10
            return sum_digits(all_but_last) + last
Comment

working of a recursive function

void recurse()
{
    ... .. ...
    recurse();
    ... .. ...
}

int main()
{
    ... .. ...
    recurse();
    ... .. ...
}
Comment

Recursive function

Please ask me about Recursive function gangcheng0619@gmail.com
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript error handling 
Javascript :: console.group in javascript 
Javascript :: ilan mask 
Javascript :: variable name as a string in Javascript function 
Javascript :: javascript canvas load image 
Javascript :: check cookie existence js 
Javascript :: call c# function from javascript 
Javascript :: audio get current time 
Javascript :: sum of a sequence 
Javascript :: mdn javascript 
Javascript :: javascript callbacks 
Javascript :: moment-recur cdn 
Javascript :: discord js role giver 
Javascript :: html get color gradient percentage 
Javascript :: How to Define a Function using a Function Expression in javascript 
Javascript :: array of array of string js 
Javascript :: como ordenar um array em ordem crescente javascript 
Javascript :: fizzbuzz in one line javascript 
Javascript :: millis javascript 
Javascript :: javascript get last emlement array 
Javascript :: javascript map callback function 
Javascript :: how to fetch web page source code with javascript 
Javascript :: array for numbers 
Javascript :: const justCoolStuff = (arr1, arr2) = arr1.filter(item = arr2.includes(item)); 
Python :: python most used functions 
Python :: postgres django settings 
Python :: display maximum columns pandas 
Python :: python print timestamp 
Python :: python list with all letters 
Python :: create conda env with specific python version 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =