manishnips.blogspost.com

What is Recursion in C ? And How it is use


/*

Hello friends !
I am Manish Gupta.
And welcome to you all at https://www.blogger.com/profile/11710251641564278815 (manishnips.net)

How are you ?
In this page I describe  Introduction of Recursion in Function and also describe the program of Function.

C programming के इस tutorial series में मैंने program लिखने और compile करने के steps बताएं हैं| मुझे उम्मीद है की यह पोस्ट आपके लिए काफी हेल्पफुल होगा| इस पोस्ट को अपने दोस्तों के साथ जरुर share करें| manishnips blog पर आने के लिए धन्यवाद|



                                                    RECURSION

# Recursion is a process in which function calls itself its body.
# It is used for Repeatetive task.
    Rules for Recursion:-1. Function must be called or invoked itself in its body.
2. Their must be an exit condition to stop Recursion.
    Types of Recursion:-
There are Two types of Recursion1. Direct Recursion:-When function calls itself in its body.ie- only one function is invoked.
Example:void num()
{
..........
..........
num();
}
2.Indirect Recursion:-For indirect Recursion two function are involed. Both call each other in their body.
Example-void num()
{
............
............
sum();
}
{
............
............
num();
}

अगर आप programming के field में अपना carrier बनाना चाहते हैं तो आपको सबसे पहले Recrtsion के basics को सीखना होगा उसके बाद ही आपको बड़े बड़े program समझ आयेंगे|




Que.. WAP to find factorial of input nos. using Recursion.

#include<stdio.h>
#include<conio.h>
int fact(int );
void main()
{
int n,t;
clrscr();
printf("Enter any number=");
scanf("%d",&n);
t=fact(n);
printf("Factorial=%d",t);
getch();
}
int fact(int x)
{
int z;
if(x==0)
return 1;
else
{
z=x*fact(x-1);
return z;
}
 }
Que... WAP to print table of inpur nos . using Recursion. 

#include<stdio.h>
#include<conio.h>
void table(int,int);
void main()
{
int n;
clrscr();
printf("Enter any no=");
scanf("%d",&n);
table(1,n);
getch();
}
void table(int x,int y)
{
if(x==10)
printf("\n%d",x*y);
else
{
printf("\n%d",x*y);
table(++x,y);
}
}
 */
  


Previous
Next Post »