+ 3
How to make a recursive function
4 Respuestas
+ 6
Recursive in Java
returntype methodname(){
//code to be executed
methodname();//calling same method
}
///////////////////////////////////////////////
public class RecursionExample1 {
static void p(){
System.out.println("hello");
p();
}
public static void main(String[]args) {
p();
}
}
+ 4
This is a C example.
https://code.sololearn.com/c3zSdRyEcdwL/?ref=app
+ 3
https://www.sololearn.com/discuss/1911868/?ref=app
https://www.sololearn.com/discuss/1294343/?ref=app
https://www.sololearn.com/discuss/488848/?ref=app
https://www.sololearn.com/discuss/311837/?ref=app
https://www.sololearn.com/discuss/1486703/?ref=app
https://www.sololearn.com/discuss/307407/?ref=app
https://www.sololearn.com/discuss/1638452/?ref=app
https://www.sololearn.com/discuss/1803477/?ref=app
https://www.sololearn.com/discuss/1013104/?ref=app
+ 1
Methodtype functionname(parameters)
{
Code
.
.
.
.
.
.
}
Call the function
Example:
Int fact(n)
{
If(n==0||n==1)
Return 1;
Else
Return n*fact(n-1);
}
Fact(n)