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

Linked list, program for singly linked list with out header

program for singly linked list with out header

Programing, #question. write a program number to alphabet in c++..

#question. write a program number to alphabet in c++..

Destruction of local object, Need assignment help What's the order that ...

Need assignment help What's the order that local objects are destructed?

C programming., #queComputers are frequently used in check-writing systems,...

#queComputers are frequently used in check-writing systems, such as payroll and accounts payable applications. Many stories circulate regarding weekly pay- checks being printed (by

Creating shopping carts, how to create a shopping cart and sibmit the code ...

how to create a shopping cart and sibmit the code segment on screan

What does odbc do in context with php, What does ODBC do in context with PH...

What does ODBC do in context with PHP? PHP supports many databases such as dBase, Microsoft SQL Server, Oracle, etc. however, it also supports databases such as filePro, FrontB

New customer, #questionhow can i add new customer and alot him a new unique...

#questionhow can i add new customer and alot him a new unique id ..

C++ programming, give a program to accept and print 2_D Array

give a program to accept and print 2_D Array

Doubt!, find the greater of the two variables, without using conditional lo...

find the greater of the two variables, without using conditional loops or ternary operators?

#title minimization and maxmization assignment problem, how we can code in ...

how we can code in c++ for assignment problem (operation research) method to mkinimization and mamization

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