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

Queue, write a queue program in c langauge?

write a queue program in c langauge?

Write a c++ program that calculates the area of a circle, Write a C++ progr...

Write a C++ program that calculates the area of a circle, rectangle and square using overloaded versions of a function area ().Your program should include both declarations and def

What does this mean that "friendship isn''t transitive, What does this mean...

What does this mean that "friendship isn't transitive, inherited or reciprocal"? A: As I grant you friendship access to me doesn't grant your kids automatically access to me, do

C programming, write a c program to solve exanple of lamis therom

write a c program to solve exanple of lamis therom

Explain processing a data file, Explain Processing A Data File? Mainly ...

Explain Processing A Data File? Mainly data file applications needs that a data file be altered as it is being processed. For instance in an application involving the processin

DECODE, Smugglers are becoming very smart day by day. Now they have develop...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Creates and implements a class to represent the queue, Purpose This ass...

Purpose This assignment is an exercise in implementing the queue ADT using a singly-linked list. This assignment also introduces the concept of templates. Assignment Th

Microprocessors and motherboards, The heart of the modern electronic system...

The heart of the modern electronic system is the microprocessor e.g. the video, sound, game consoles, portable phones and domestic appliances. Let us consider the heart of a home c

Write program to get largest element in array using function, Write a progr...

Write a program to get the largest element in an array using Function? # include int largest(int b[],int); main() { int lar,a[5]={12,2,36,40,5}; lar=largest(a,n); printf("

C program for function of average, C program for function  of average ...

C program for function  of average int average(int); void main() {           int max=0,c=0;           clrscr();           printf("ENTER THE LIMIT OF INPUT FOR AV

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