Explain recursion with an example.



Explain recursion with an example...

Answer / nashiinformaticssolutions

o Recursion is a technique where a function calls itself to solve smaller sub-problems.
8. def factorial(n):
9. if n == 1:
10. return 1
11. else:
12. return n * factorial(n - 1)
13. print(factorial(5)) # Output: 120

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Programming Languages AllOther Interview Questions

What is %Type,%Rowtype?

1 Answers  


What are the compilers of JAVA and .NET Programming languages?

1 Answers   HCL, Microsoft,


What Is The Difeerence Between C & C++

2 Answers   HCL,


what is difference between restoring and non restoring division?

2 Answers   Texas,


10.Define filters,binary to hexadecimal,hexadecimal to decimal?

1 Answers  


What is the use of sas software? Is sas and sap are different?

1 Answers  


Write a function which accepts a sentence as input parameter.Each word in that sentence is to be reversed. Space should be there between each words.Return the sentence with reversed words to main function and produce the required output. for eg:- i/p: jack jill jung kill o/p: kcaj llij gnuj llik

1 Answers   Mind Tree,


In OB52 , How to define two open posting period, Like only 5 and 8 posting should be open.. should not open 6 and 7..period..

1 Answers  


what is the difference between a namespace and assembly ?

4 Answers   Innominds, Polaris,


What is the effect of the OPTIONS statement ERRORS=1?

3 Answers   QSG, Quintiles, SAS,


I would like to know which institute in hyderabad provides best ms-dot net training along with a project. I want to join immediately. please help

2 Answers  


what are all the validation we need to perform in data stage?

1 Answers  


Categories