<br>
ydansa.
Asswer: til
clase Reesti
Shing Sh ,keost,
[Link];
Syste.
vold hecRenel int 2)
4cizo)
110 Rewst z kesct +
sa,hatt () Rect
<br>
stdchek)
keclnere(ssenhc-)
4caequalelkenst))
syteiut frintln(ee gtia Paltndieme
sing
blie taie uaid main(oung aiga.C
fcheckc)s
Recursion 111
recursive tl co
main() fun
<br>
PrintPrimes() of the
details the
void
giving the )
Detine
num, nt y)?
thesericsPrintPrimes
task. IsPrime(nt
ciuss votd cHablc the
functíon int
Srecify the arid
iat siriment, int)B:CTdingly fo
the nthos
trine
Hbils
all o tak
CTewil
*07
t liimit
fos (it i-
o
;4<is;tt)
112
<br>
for(int
asiJ-sconenItc
LsPlme (iit nemnty)
Aetum IsPsine (nmy -1);
113
Recursion
<br>
-neo theseiu
mesc
<br>
cass defines,
Ciheck a
recursive function to performn string related
A beelow: operations. [Link] of
given the class
Class name Check
Data members/instance variables
Str to storc string.
W integer variablc.
Member functions/methods
void InputString() to read the string from input.
void Counter( int :
to count total number of words starting with capital
)
vowels
and store in w.
void Disp( ): by calling recursive function Counter(..) display the string
and result stored in w,
Snecify the class Check giving details of the functions void
InputString ), void Counter(int)
and yoid Disp( ). Define a main( ) function to create an
object call the methods to print the output.
What happens if the Base Case is removed from the Recursion? Give one example also.
Answer:
awa,tily,
class Cheek
ScammeA SC
welSyslentind;
[Link](etenster a sting");
Recursion
<br>
chas chz [Link]()
CeunttalitD;
Counte (o) "
Syste, [Link] (eSoa:
s)
<br>
Date:
a
Binary defines recursive function to convert a
binary nunber into
alapie': Let Binary number: 1101. its cquivalent
decimat
its equivalent decimal
lx2'+1x2+x2'+1x2=8+4+0+1 form.
cdetais of the class are given below : 13.
Tlhe
Class name Binary
Data members/instance variables
bin long integer data to store
iec binary number.
long integer data to store
decinnal numbher.
Member functions/methods
Binary() detault constuctor.
void teadBin( )
to reada binary number in bin.
long convertDec(long) to convert the binary
nnter stored in bin
decimal using Recursive Technique. into its cquivalent
Store the decimal
number into dec and rcturn.
void Show(): to display the binary number and its
equivafent decimal
number stored in dec by invoking the recursive
Snecify the ciass Binary giving details of the constructor
fnction.
and void read Bin( ). long
onyertDec(long) and void Show( ). Define a main( ) function to create an
object and invoke the
methods accordingiy to enable the task.
a
With the help of one example specify that how the recursive process works in
LIFO form?
Answer:
puble ilas Binasy
leng bin,eees
Binay C)
bin0s
deeo
nnbea ;
bin z [Link]);
Recursion
<br>
4(6-o)
iton (b %1c) + 2*consetDeclb/ro);
Meld Showt)
dec cerveAtDecChin)o
System. tfrinineBinasy nnhle.
<br>
Answer:
inypett janautily
cles lecBn
die BinO
vsid
cursion 11
);
<br>
hcersive (unt p)
Mofd
Ricssine (p/ 2);
woid putdata)
Sytem, ondiprintln(t a yialent
birasy nmbet
+
Aecose n))
<br>
Answer:
nyotautil.*
class Change
Scamcs Sc Scane(syen au);
Gnder a wsond).
Systemnmtfrltl(et
ne
SA2Sc.
Recursion
<br>
elie
setusm ch
P
vetid 2ecehargc (int
c= sthcharttlp)
7remslet= Cascceweil)
Syoemotfpriklnle Changedl wgrc
pabticetaticvel main(steng asgs 3)
Rec:
<br>
Answer:
jatatil;
nissie
clas
nt
Adnisslen(nt in)
Scamneh St neut Scanon/sstemo,n);
Sytonatitn( ender adisien nunbes")
123
ecursion
<br>
U)
hetum
binseasch Cmtl, u, v)
Retutn
publiestte veid man(sheng angD
Adminion otojemeus dnission);
[Link](e6 Ente value-toiesesscl
aitp [Link], oejiAlro,
lells
clye
forend
inpol [Link]
<br>
bublic class smseies
int
cleubie sm
Surn Sewesl5
n20:
Sur 0.0;
wgid neadllimitcs
Scammes scms Scammea/Sstert an 125
ante
Cursion
System,otintln amdn);
<br>
ond
gettrso(int n,
int p
wold
Surml)
on(indie2;<n;dt
Sumt=
}
publie statie
voidmain(slbing
sgrl