Explain recursive functions, C/C++ Programming

Assignment Help:

Recursive Functions

Recursion is a process by which a function includes itself with a condition for its safe exit. It is best suitable for a recursive problem. A typical example is the factorial problem, the programs without and with recursive functions are shown below.

void main()

 {

   long factorial ( int num); // Forward declaration of

       //a function

   int num;

printf("\n Enter a number:");

scanf("5d",&num);

printf(" Factorial of 5d is %ld",num,factorial(num));

  }

long factorial(int num)   // Non recursive

 {

   long f=1;

while ( n)

                 {

                   f = f * n;

                   n--;

                 }

                return(f);

 }

long factorial(int num)   // Recursive

 {

                if(n == 1)

                                return (1);

                else

                                return( n* factorial(n-1));

 }

 


Related Discussions:- Explain recursive functions

Simple object-oriented program, This assignment is to be undertaken individ...

This assignment is to be undertaken individually - no group work is permitted. Background information This assignment is an exercise in simple object-oriented programming and, acco

#pointers, what is the purpose of pointer ? what is the syntax? how it work...

what is the purpose of pointer ? what is the syntax? how it works?

Stack, Implement multiple stacks in a single dimensional array. Write algor...

Implement multiple stacks in a single dimensional array. Write algorithms for various stack operations for them.

Padovan sequence, write a program that counts the number of occurrences of ...

write a program that counts the number of occurrences of the string in the n-th Padovan string P(n)

Files, redirection in c++

redirection in c++

Explain the function of five elements that are on a, explain the function o...

explain the function of five elements that are found on a motherboard#

Program to define simulation method, This problem familiarizes you with usi...

This problem familiarizes you with using random numbers in C++. The program is to compute a good approximation of π using a simulation method called "Monte Carlo". The following fi

Srand and rand(), Mention clearly about srand and rand().

Mention clearly about srand and rand().

Database, write a c++ program to update employee records

write a c++ program to update employee records

Assyrian keyboard for android, Project Description: I want an app that t...

Project Description: I want an app that the user can download it from the play store and use it as a keyboard for texts and writing. Just like the Samsung keyboard and the arabi

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd