answersLogoWhite

0


Best Answer

Recursion is the technique of a function calling itself, rather than iterating through the use of loops. The classic example of a recursive function is the computation of N Factorial...

int nfact (int n) if (n 5, for instance, it will call itself an additional 3 times, so you will have 4 stack frames where the local value of n is 5, 4, 3, and 2. When you get to the last call, you unwind the stack frames, and the multiplication of 2, 3, 4, and 5 takes place.

This example is for illustration only. It fails miserably with even small values of n (13, using 32-bit arithmetic) due to integer overflow, because N Factorial get large quickly.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

int factorial (int n) {

if (n == 1) return 1;

else return factorial (n - 1) * n;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is recursion in c explain with the help of an example?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between left recursion and right recursion in a grammar?

Recursion is what it's called when a function calls itself. When a function calls itself immediately before returning, it's called tail recursion. Tail recursion can be more efficiently written as iteration. In fact a good compiler will recognize tail recursion and compile it as iteration. There is no such thing as left or right recursion in C programming.


What is the C program for heap sort using recursion?

123


How many types of recursion are there in c language?

Recursion in c language is a method where the function calls itself, within or outside the scope. Using Recursion, complicated problems can be divided into smaller parts so that solving them becomes more manageable. The recursion technique is available in Java, JavaScript, and C++.serves the same purpose. The type of Recursion in C • Direct Recursion • Indirect Recursion. Direct Recursion Recursion can call the function n-number of times. In the case of direct Recursion, the function calls itself inside the same position or in the local scope Direct Recursion problems are the Fibonacci series, a program to print 50 natural numbers. Indirect Recursion In the case of Indirect Recursion, a function X calls function Y, and function Y calls any function Z. Under certain conditions, function Z calls function A. In this case, function A is indirectly related to function Z. Indirect Recursion is also known as mutual Recursion, as more than one function runs a program. It is a two-step recursive function call process for making a recursive function call. Below mentioned are also type of Recursion: Tail Recursion No Tail/Head Recursion Linear Recursion Tree Recursion Tail Recursion A function is said to be tail recursion if it calls itself and also calls the last or the previous statement executed in the process. Head Recursion A function is said to be Head Recursion if it calls itself and also calls the first or the beginning statement executed in the process. Linear Recursion A function is said to be a linear recursive function if it makes a single call to itself each time the procedure executes itself and grows linearly depending on the size of the problem. Tree Recursion Tree Recursion is different from linear Recursion. Rather than making only one call to itself, that function makes more than one recursive call to the process within the recursive function. Following are the steps to solve the recursive problem in C: Step 1: Create a function and assign the work a part should do. Step 2: Select the subproblem and assume that the function already works on the problem. Step 3: Get the answer to the subproblem and use it to resolve the main issue. Step 4: The 90% of the problem defined is solved.


Explain the following tearm in the context of object oriented programming Also explain how these concept are implement in c by given an example program for each?

Explain the following terms in the context of object oriented programming. Also explain how these concepts are implemented in C++ by giving an example program for each.


Explain pointer to function with example c language?

It isn't a question, sorry.


What are floating point numbers How are they initialized in C program Explain with the help of one example?

dadur bichi fulko luchi............... tor tadur pode fuler bichiii...................... bujli chudir-bhai


How java is different from c plus plus Explain with example?

See related links, below.


Explain using an example how destroying the balance between predator and prey in a community can upset the ecology of an area?

c


A circular-flow diagram is a model that?

A)help to explain how partipant in the econmy interact with one other . B)help to explain how the economy is organized . C)incorporate all aspects of the real economy. D)Both (a)and (b) are correct


Explain the Abstraction terms in the context of object oriented programming Also explain how these concepts are implemented in C by giving an example program for each?

g terms in the context of object oriented programming


What is advantages of recursion in a data structure?

Recursive procedures are huge memory hogs. Also, they're a nightmare to debug. Finally, it's pretty rare to find an application that actually needs recursion as opposed to a simpler, more friendly methodolgy.


C program for summation of n nos using recursion?

int sum (int n) { if (n<=1) return n; else return n + sum (n-1); }