JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: C Language in hindi

C : Recursion : Examples in c programming language in hindi , Recursion example programs

Recursion example programs , C : Recursion : Examples in c programming language in hindi :-
इससे पहले के article मे , recursion से related उदाहरण को discuss किया था |अब इस article मे , recursion से related पांच और उदाहरन को पढ़गे |
उदाहरण -1
Write a program to print strong numbers in range .
इस उदाहरण मे , recursion process से किसी range के सभी strong numbers को print करते है |
Explanation
Strong number  एसी number होती है जिसका factorial का sum ,number के equal होता है |
1.सबसे पहले , यूजर से range की start और end को input करा लेते है |
2.इसके बाद function print() को call करते है जिसमे start और end को pass करते है |
print() मे ,
अगर start की value end से कम नहीं होती तब , number को start से initial करते है |इसके बाद loop चलाया जाता है |
1.जब तक number के value ‘0’ नहीं होती है तब sum operation perform करते है |
sum operation मे , recursion प्रोसेस मे fact() function को call करेगे और इस function मे number = number /10 से डिवाइड करेगे |
2.जब start के value sum से सामान होती है तब start को print करेगे |
fact () function मे ,
अगर num की value 0 होती है  तब ‘1’ return होगा |
अन्यथा रिकर्शन process से fact () function को call करेगे |
Source Code
#include<stdio.h>
#include<conio.h>
int fact(int number);
void print(int , int );
void main()
{
int start, end;
printf(“Enter Start “);
scnaf(“%d”,&start);
printf(“Enter End”);
scnaf(“%d”,&end);
printf(“Strong number in list “);
print(start , end );
getch();
}
void start (int s ,int e )
{
int sum;
int number ;
while(s!=end)
{
sum=0;
number = start ;
while (number!=0)
{
sum = sum + fact (number % 10 );
number = number / 10 ;
}
if(s == sum)
{
printf(“%d”,s );
}
s++;
}
}
int fact ( int num )
{
if(num==0)
{
return 1;
}
else
{
return (num * fact(num -1)) ;
}
उदाहरण -2
Write a program to print reverse of the number  .
इस उदाहरण मे , recursion process से किसी number  को reverse  print करते है |
Explanation
1.सबसे पहले , number को input करा लेते है |
2. उसके बाद reverse() function को call कर लेते है |
reverse function मे ,
इस function मे number को 10 से डिवाइड करते है और इसके remainder को print करते है |
divide function  को call करते है जिसमे number / 10 को pass करते है |
Source Code
#include<stdio.h>
#include<conio.h>
int div(int );
void reverse(int);
void main()
{
int num;
printf(“Enter Number”);
scanf(“%d”, &num);
printf(“Reverse Number”);
reverse(num);
getch();
}
void reverse (int n )
{
int r;
while (n!=0)
{
r=div(n/10);
printf(“%d”,r);
n/10 ;
}
}
int div(int n)
{
return(n % 10 );
}
उदाहरण -3
Write a program to print Fibonacci series  .
इस उदाहरण मे , recursion process से Fibonacci series  print करते है |
Explanation
1.सबसे पहले , Fibonacci series का number elements को input करते है |
2.इसके बाद fib() function को call करते है |इस फ़ुन्क्तिओन्न मे ‘0’ ,’1′ और number of elements को पास कर देगे |
fab() मे ,
1. loop चलाया जाता है | इस loop को जब तक चलाया जाता तब तक i की value size के सामान नहीं हो जाती है
इस loop की body मे , a+b की value को print किया जाता है
recursion process से fab() को call किया जाता है जिसमे a और b के value increment किया जाता है |
Source Code
#include<stdio.h>
#include<conio.h>
int fab(int , int , int );
void main()
{
int l ;
printf(“Enter number of element “);
scanf(“%d”,&l);
fab(0,1,l);
getch();
}
fab(int a , int b ,int len)
{
int i;
for(i=0;i<len;i++)
{
printf(“%d”, a+b));
fab(a++,b++,len)
}
}
उदाहरण -4
Write a program to find nth term of Fibonacci series  .
इस उदाहरण मे , recursion process से nth term of Fibonacci series  find करते है |
Explanation
1.सबसे पहले , यूजर से series मे से किस position के टर्म को find करना है उस position की value input करा लेते है |
2.फिर उसके बाद fab() function कोप call कर लेते है जिसकी value को int f मे assign कर लेते है |
3. इस variable ‘f’ की value को print करा लेते है |
fab() function मे ,
अगर number के value ‘0’ होती है तब ‘0’ return होता है |
अगर number की value ‘1’ होती है तब ‘1’ return होता है |
अन्यथा
रिकर्शन प्रोसेस से function fab() को call कर लेते है जिसमे number-1 और number-2 को pass करा लेते है |
Source Code
#include<stdio.h>
#include<conio.h>
int fab(int );
void main()
{
int l ;
printf(“Enter number “);
scanf(“%d”,&l);
int f;
f=fab(l);
printf(“Nth term of seriers = %d”,f);
getch();
}
int fab(int num)
{
if(num ==0)
{
return(0);
}
else if (num==1)
{
return 1;
}
else
{
return (fab(num-1) +fab(num-2));
}
}
उदाहरण -4
Write a program to find LCM of two numbers.
इस उदाहरण मे , recursion process से  दो number का lCM find करते है |
Explanation
1.सबसे पहले , यूजर से series मे से किस position के टर्म को find करना है उस position की value input करा लेते है |
2.फिर उसके बाद fab() function कोप call कर लेते है जिसकी value को int f मे assign कर लेते है |
3. इस variable ‘f’ की value को print करा लेते है |
fab() function मे ,
अगर number के value ‘0’ होती है तब ‘0’ return होता है |
अगर number की value ‘1’ होती है तब ‘1’ return होता है |
अन्यथा
रिकर्शन प्रोसेस से function fab() को call कर लेते है जिसमे number-1 और number-2 को pass करा लेते है |
Source Code
#include<stdio.h>
#include<conio.h>
int lcm(int ,int );
void main()
{
int a , b , l  ;
printf(“Enter first number “);
scanf(“%d”,&a);
printf(“Enter Second Number”);
scnaf(“%d”,&b);
if(a<b)
{
l=lcm(a,b);
}
else
{
l=lcm(b,a);
}
printf(“LCM = %d”, l );
getch();
}
int lcm(int i ,int j )
{
static int m=0;
m= m +j;
if((m % i = =0) && (m% j ==0)){
return(m);
}
else
{
return lcm(i,j);
}
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