JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

Recursion : Examples in c language in hindi , in c programming what is Recursion Example

in c programming what is Recursion Example ,  Recursion : Examples in c language in hindi :-
इस article मे   Recursion  से related उदहारण को discuss करेगे | जिससे   Recursion  concept को अच्छी तरह से समजा जा सके | क्योकि    Recursion  को कई सारे appliactions मे use किया जाता है | इसलिए   Recursion  के concept को पढना बहुत जरुरी है |
उदहारण 1:
Write a program to calculate power using  Recursion function.
इस उदाहरण मे , Recursion function से power को calculate करना है |
Explantation
1.सबसे पहले यूजर से power और base की value input करा लेते है |
2.इसके बाद power() function को call करते है जिसमे power और base की value pass करते है |
3. function power () से return value को output variable”output’ मे assign करके print करा देते है |
power () function ,
power() function मे ,
अगर power ‘0’ है तब power function की value ‘1’ return होगी |
और अगर power की value ‘पॉजिटिव है तब base की power power को solve करते है |इसके लिए base और power(base , power-1) से calculate करते है |
अगर power की value negative है तब 1/base की power power को calculate करते है |
Source Code
#include<stdio.h>
#include<conio.h>
int power (int int );
void main (()
{
int base , power ;
printf(“Enter Base value : “);
scanf(“%d”,&base);
printf(“Enter Power Value : “);
scanf(“%d”,&power);
int output = power (base , power );
printf(“Output = %d “, output );
getch();
}
int power (int c, int d)
{
int o;
if(d==0)
{
return ( 1);
{
else if(d>0)
{
o=c * power (c , d-1);
}
else
{
o=1/power (c , -d);
}
return (o);
}
आउटपुट होगा :
Enter Base value : 3
Enter Power Value : 3
Output = 27
उदहारण 2:
Write a program to calculate sum of integers using  Recursion function.
इस उदाहरण मे , Recursion function से integers के sum को calculate करना है |
Explanation :
1.सबसे पहले यूजर से start और  end की value input करा लेते है |
2.इसके बाद sum () function को call करते है जिसमे start  और end की value pass करते है |
3. function power () से return value को output variable”output’ मे assign करके print करा देते है |
sum () function मे ,
इस function मे , सबसे पहले condition check होगी | जब तक start की value , end से कम होगी तब
Recursion method से function sum() को call किया जाता है | इस function मे start +1 को pass किया जाता है |
अन्यथा output को return करते है |
Source Code
#include<stdio.h>
#include<conio.h>
int sum (int int );
void main (()
{
int start , end  ;
printf(“Enter Starting value : “);
scanf(“%d”,&start);
printf(“Enter Ending Value : “);
scanf(“%d”,&end);
int output = sum ( start  , end );
printf(“Output = %d “, output );
getch();
}
int power (int s, int e)
{
int o=0;
if(s<c)
{
o=o+sum(s+1,e);
}
else
{
return (o);
}
}
आउटपुट होगा :
Enter Starting value : 1
Enter Ending Value : 12
Output = 78
उदहारण 3 :
Write a program to print integers between range using  Recursion function.
इस उदाहरण मे , Recursion function से किसी range के बीच  integers को print करना है |
Explanation :
1.सबसे पहले यूजर से start और  end की value input करा लेते है |
2.इसके बाद print () function को call करते है जिसमे start  और end की value pass करते है |
3. function print () मे , range के बीच की सभी integers को print करती है |
sum () function मे ,
इस function मे , सबसे पहले condition check होगी | जब तक start की value , end से कम होगी तब print statement मे Recursion method से print() function को call किया जाता है जिसमे की start को start +1 से pass करते है |
Source Code
#include<stdio.h>
#include<conio.h>
void print(int , int );
void main (()
{
int start , end  ;
printf(“Enter Starting value : “);
scanf(“%d”,&start);
printf(“Enter Ending Value : “);
scanf(“%d”,&end);
print( start  , end );
getch();
}
void print(int s, int e)
{
if(s<=c)
{
printf(“%d \t “,s);
}
else
{
exit ;
}
print(s+1 , e );
}
आउटपुट होगा :
Enter Starting value : 1
Enter Ending Value : 12
1 2 3 4 5 6 7 8 9 10 11 12
उदहारण 4 :
Write a program to print even or odd integers between range using  Recursion function.
इस उदाहरण मे , Recursion function से किसी range के बीच even or odd integers को print करना है |
Explanation :
1.सबसे पहले यूजर से start और  end की value input करा लेते है |
2.इसके बाद print () function को call करते है जिसमे start  और end की value pass करते है |
3.function print () मे , range के बीच की सभी even or odd integers को print करती है |
4.इसके लिए , दो function even () और odd () को call किया जाता है |
even () function मे ,
इस function मे , सबसे पहले condition check होगी | जब तक start की value , end से कम होगी तब print statement मे सबसे पहले even number print होगा | Recursion function से print() function को call किया जाता है जिसमे की start को start +2 से pass करते है |
odd () function मे ,
इस function मे , सबसे पहले condition check होगी | जब तक start की value , end से कम होगी तब print statement मे सबसे पहले odd number print होगा | Recursion function से print() function को call किया जाता है जिसमे की start को start +2 से pass करते है |
Source Code
#include<stdio.h>
#include<conio.h>
void even ( int , int );
void odd( int ,int );
void main ()
{
int start , end  ;
printf(“Enter Starting value : “);
scanf(“%d”,&start);
printf(“Enter Ending Value : “);
scanf(“%d”,&end);
if(start  % 2 == 0)
{
print (“Even numbers “);
even ( start  , end );
printf(“Odd number “);
odd(start-1,end);
}
else
{
print (“Even numbers “);
even ( start+1 , end );
printf(“Odd number “);
odd(start,end);
}
getch();
}
void even (int s ,int e)
{
if(s<=e)
{
printf(“%d \t “,s);
}
else
{
exit ;
}
print(s+2 , e );
}
void odd(int s ,int e )
{
if(s<=e)
{
printf(“%d \t “,s);
}
else
{
exit ;
}
print(s+2 , e );
}
आउटपुट होगा :
Enter Starting value : 1
Enter Ending Value : 12
Even number
2 4 6 8 10 12
Odd number
1 3 5 7 9 11
उदहारण 5 :
Write a program to print elements of array  using  Recursion function.
इस उदाहरण मे , Recursion function से किसी array के सभी elements को print करना है |
Explanation :
1.सबसे पहले यूजर से array से value input करा लेते है |
2.इसके बाद print () function को call करते है जिसमे array का नाम , starting point की value pass करते है |
3. function print () मे , array के सभी elements को print करती है |
sum () function मे ,
इस function मे , सबसे पहले condition check होगी | जब तक start की value , length से कम होगी तब print statement मे array के start position के element print होगा | Recursion method से print() function को call किया जाता है जिसमे की start को start +1 से pass करते है |
Source Code
#include<stdio.h>
#include<conio.h>
void print(int , int );
void main (()
{
int a[5];
printf(“Enter data :  “);
for(i=0;i<5;i++)
{
scanf(“%d”, a[i]);
}
printf(“Array Element \n “);
print(a, 0 ,5);
getch();
}
void print(int arr[], int start , int size )
{
if(start < size )
{
printf(“%d\n “,arr[start]);
}
print(arr , start+1 , size);
}
आउटपुट होगा :
Enter data : 3 4 5 6 7
Array Element
3
4
5
6
7
Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now