0% found this document useful (0 votes)
6 views9 pages

5 Recursion

Repitstion of them

Uploaded by

lovely143yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

5 Recursion

Repitstion of them

Uploaded by

lovely143yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Main

Using Recursion Find

1.Sum upto N-Natural


nos.
2. GCD of 2-
nos.
3. Factorial of a
no.
4. Fibnocci Series upto N-terms.

Integer ch

String YN

Output "Using Recursion


Find
;
1.Sum upto N-Natural
nos.
2. GCD of 2-
nos.
3. Factorial of a
no.
4. Fibnocci Series upto N-
terms.
Ur Choice ::"

Input ch

False True
ch != 1

False True
RecSumOfN ( )
ch != 2

False True
RecGCD ( )
ch != 3

False True
RecFact ( )
ch != 4

RecFib ( ) Output "Wrong i/p !!!"

Output "Wanna continue?


( Y / N )"

Input YN

True

Char( YN , 0 ) = "Y" or Char


( YN , 0 ) = "y"

False

Output "THANKS ! GOOD


BYE ! GOOD LUCK !"

End
Fact
(Integer n)

Integer f

f=1

False True
n >= 1

f = n * Fact ( n-1 )

Return Integer f
Fib
(Integer n)

Integer f

False True
n=0

False True
f=0
n=1

f = fib(n-1) + fib(n-2) f=1

Return Integer f
GCD
(Integer x, Integer y)

False True
y != 0

Output "GCD of given 2 GCD( y, x%y )


nos. is " & x

End
RecFact

Output "Flowgorithm to find


Factorial of a number !"

Integer n

Output "Enter a no. :: "

Input n

False True
n>0

Output "Wrong i/p !!!" Output "Factorial of a given


no. is :: " & Fact(n)

End
RecFib

fibnocci series starts from 0 & 1 as 1st &


2nd
term.
the next term is sum of previous two
terms...

Output "Flowgorithm to find


the Fibnocci series for N-
terms"

Integer n, i

Output "Enter how many


terms you want in Fib
series ? :: "

Input n

Output "Fib series of " & n &


" term is :: "

Next
i = 0 to n-1

Done
Output Fib ( i ) & " , " …

End
RecGCD

Output "Flowgorithm to find


the GCD of 2 nos. "

Integer m, n

Output "Enter 2 nos. ::"

Input m

Input n

GCD(m,n)

End
RecSumOfN

Output " Flowgorithm to find


the SUM OF N-Natural
Nos. "

Integer n

Output " Enter value for n


:: "

Input n

False True
n>0

Output "WRONG I/P!!!" Output "Sum Upto " & n & " -
Natural nos. is :: " & SumOfN
(n)

End
SumOfN
(Integer n)

Integer sum

sum = 0

False True
n != 0

sum = n + SumOfN ( n-1 )

Return Integer sum

You might also like