The function which is
called by itself is called recursion.
OR
When function is called
within the same function, it is known as recursion.
Example:
#include<iostream.h>
#include<conio.h>
void main()
{
int fact(int);
int i,f,num;
clrscr();
cout<<"Enter
any number: ";
cin>>num;
f=fact(num);
cout<<"Factorial:
"<<f;
getch();
}
int fact(int a)
{
if(a<0)
return(-1);
if(a==0)
return(1);
else
{
return(a*fact(a-1));
}
}
Output:
Enter any number:5
Factorial:120
Python is an open-source, high level, interpreted programming language which offers great opportunities for object-oriented programming. Choosing a python training program from Red Prism Group, which is best training institute for python in noida.
ReplyDelete