+ 4

What is recursion function?

12th Jan 2018, 5:03 PM
Puneet Bhardwaj
Puneet Bhardwaj - avatar
6 ответов
+ 11
here if n is 3 for example it will decrease to 2 then to 1 , so when it reaches 1 it returns 3×2×1.(n*factorial(n-1)) bcz it knows what to return when n=1 .
13th Jan 2018, 12:22 PM
Anon Fox
Anon Fox - avatar
+ 8
a recursion function is a function that repeats its self unless it finds a value to stop on and u declare this value ex : #include<stdio.h> unsigned factorial (int n) { if (n==0 || n==1) return 1 ; else return n*(factorial(n-1) ); } void main () { int n ; printf("enter a number"); scanf ("%d", &n); printf ("answer : %d!= %u ",n,factorial(n)); }
13th Jan 2018, 12:16 PM
Anon Fox
Anon Fox - avatar
+ 2
in simple terms its just a function calling itself repeatedly
5th Feb 2018, 4:37 PM
Sneha Regi Thomas
Sneha Regi Thomas - avatar
+ 1
This is a function that looks like a loop, but the exit condition of the function always lies in the function. Sample: #include <iostream> int rec(int i){ if(i>10) return i; i++; rec(i); } int main(){ int i=0; std::cout<<rec(i); } output: 11 for better understanding, you need to remember the theory of the graph.
13th Jan 2018, 4:30 AM
Семён Седов
0
A function that is called by itself😊
11th Sep 2020, 10:37 AM
Lokeswari