Recursion - .OnlineGuruji

.OnlineGuruji

Provides E-Notes,Video Tutorials And Download Links For Students In hindi

*********************************************************

*********************************************************
********************************************************************************

Breaking

Ramchandicollege Saraipali

Technology Jobs

OnlineGuru Blog मे आपका स्वागत है ब्लॉग से संबन्धित जानकारी के लिए संपर्क करें मो ॰ नम ।-9826026747(सपन कुमार दास) अपने विषय से संबन्धित अपडेट प्राप्त करने के लिए ब्लॉग पे दिये गए Bell Icon को press करें कम्प्युटर,Science,English Grammer से संबन्धित विषय की अधिक जानकारी के लिए हमारे ब्लॉग अथवा यू ट्यूब चैनल को सब्क्राइब करे ..

Monday, December 19, 2022

Recursion






C language में, Recursion एक प्रक्रिया है जिसमें एक function अपने आप को बार-बार call करता है. इस function को recursive function कहते हैं. इस प्रकार की function call को recursive calls कहा जाता है.

Recursive functions बहुत सारीं mathematical problems को solve करने में बहुत उपयोगी होती है जैसे किएक number के factorial को calculate करना, fibonacci series को जनरेट करना आदि.

Advantage of Recursion in Hindi – रिकर्शन के लाभ

1.    यह अनावश्यक function call को कम करता है.

2.    इसके द्वारा हम problems को आसानी से solve कर सकते है क्योंकि iterative solution बहुत बड़ा और complex (कठिन) होता है.

3.    यह हमारे code को elegant (सुंदर) बना देता है.

Disadvantage of Recursion in Hindi

1.    Recursion का प्रयोग करके बनाये गये program को समझना और debug करना मुश्किल होता है.

2.    इसके लिए हमें ज्यादा memory space की आवश्यकता होती है.

3.    इसमें program को execute करने में ज्यादा समय लगता है.

 Types of Recursion in C in Hindi – रिकर्शन के प्रकार

इसके प्रकार निम्नलिखित हैं:-

1:- Tail Recursion  – यदि एक recursive function खुद को call करता है और यह recursive call, फंक्शन का अंतिम statement है तो इसे tail रिकर्शन कहते हैं. इस recursive call के बाद फंक्शन कुछ भी perform नहीं करता है.

2:- single recursion – इस प्रकार के रिकर्शन में केवल एक recursive call होती है.

3:- Multiple recursion – इस प्रकार के रिकर्शन में बहुत सारीं recursive calls होती हैं.

4:- indirect recursion – यह रिकर्शन तब घटित होता है जब एक function दूसरे function को call करता है जिसके कारण उसे original function को call करना पड़ता है.

Recursion का syntax –

इसका basic syntax नीचे दिया गया है:-

void recurse()

 

{

 

 

recurse();

 

 

 }

 int main()

{

 

 recurse();

 

}


Recursion:-The functuion call itself is known as recursive function and the process is known as recursion

1 Write a program to calculate the factorial of given number using recursive function

 

#include<stdio.h>

#include<conio.h>

int fact(int n)

{

 int f;

 if (n==1)

 {

  return(1);

 

 }

 else

 {

  f=n*fact(n-1);

 }

 return(f);

}

 void main()

{

        int num=1;

        int ans=fact(num);

        printf("%d",ans);

 getch();

}

2.Write a program to calculate the su of n natural number using recursive function

#include<stdio.h>

#include<conio.h>

int sum(int n)

{

 int s;

 if (n==1)

 {

  return(1);

 

 }

 else

 {

  f=n+sum(n-1);

 }

 return(f);

}

 void main()

{

        int num=1;

        int ans=sum(num);

        printf("%d",ans);

 getch();

}

No comments:

Post a Comment