c recursion

Solutions on MaxInterview for c recursion by the best coders in the world

showing results for - "c recursion"
Anthony
04 Feb 2020
1// Basic Recursive function
2// It works in all languages but lets try with C
3
4// lets make a greedy strlen
5
6int my_recursive_strlen(int index, char *str) // note that index must be set at 0 to work in this case
7{
8  if (str[index] == '\0')
9    return index + 1;
10  else
11    return my_recursive_strlen(index++); // i send index + 1 to next function call
12  // this increment index in our recursive stack
13}
14
15void main(void)
16{
17  printf("length of Bonjour = %d\n", my_recursive_strlen(0, "bonjour"));
18}
19
20//output : length of Bonjour = 7
21
22// Recursive functions are greedy and should be used in only special cases who need it
23// or who can handle it.
Bernadette
07 Apr 2019
1#include <stdio.h>
2
3int fibonacci(int i) {
4
5   if(i == 0) {
6      return 0;
7   }
8	
9   if(i == 1) {
10      return 1;
11   }
12   return fibonacci(i-1) + fibonacci(i-2);
13}
14
15int  main() {
16
17   int i;
18	
19   for (i = 0; i < 10; i++) {
20      printf("%d\t\n", fibonacci(i));
21   }
22	
23   return 0;
24}
queries leading to this page
recursive method cquestions on recursion in ctough questions on recursionc recursion programvariables in recursive functions crecursive function in c examplerecursive in crecursive in c seriesrecursive function cc recursionrecursion programs in cpractice c recursionrecursion codes for practicepractise c recursion questionshow to do recursion in crecursion questions in crecursive crecursion in c examplerecursive functions in cquestions on recursive functions in cprogram of recursion in crecursion program practicwhat do u mean by recursion in crecursion program practiceexplain recursion in c with examplerecursion example in cexercise on recursive functions in crecursion exercises chow to write a recursive function in cexplain the concept of recursion in crecursion problem solving in ccode recursion in cc program 1 to 4 recursionwhat is recursion in cc recursive macrorecursion exercisesrecursion in c programming questionsbasic questions on recursion for practicedefine recursion in cinterview questions on recursion in crecursive program in cwhat is mean by recursion in c programming languagerecursion c programquestions about recursion functions in cfunctions recursion in cc programming recursionrecursive function variable cprogram on recursion in cdefine recursion in c programmingfunction in c recursionexample of recursion in crecursion exerciserecursion in c problemsproblems on recursion cexplain recursion with example in crecursion problems in cr c3 a9cursivit c3 a9 chow to get the solution out from a recursion in cgood questions on recursion in crecursion i crecursion c program examplesrecursive finctions in ccan you do recursion in crecursion program in crecursion in c questionsrecursion questions gfgrecursion function in crecursion definition in crecursive function in crecursion meaning in cways to do recursion in crecursion algorithm in crecursin in crecursion c programmingwhat is a recursion in crecursive void function in crecursion c problemsrecursion means in c languagesrecursion tree in crecursion in c programmingrecursion in c examplesc programs using recursionrecursion questionsexamples on recursion in cc problems on recursionrecursive function in c exercisesrecursion explained in crecursion in cwhat is using recursion in crecursive programming cproblems on recursion in cprograms using recursion in cpractice exercises on recursive functions crecursive algorithm crecursive function exercisesrecursion function crecursion codes for practice in cwhat is recursion with example in chow to make recursive function in cfunction and recursion in crecursion cc recursion