Click here to Skip to main content
15,920,217 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: about voice chat between a client and a server Pin
Atif Mushtaq22-Oct-03 21:22
Atif Mushtaq22-Oct-03 21:22 
GeneralRe: about voice chat between a client and a server Pin
yingkou24-Oct-03 20:01
yingkou24-Oct-03 20:01 
GeneralRestrict window space for child process Pin
paulb22-Oct-03 19:00
paulb22-Oct-03 19:00 
GeneralRe: Restrict window space for child process Pin
Ravi Bhavnani22-Oct-03 21:06
professionalRavi Bhavnani22-Oct-03 21:06 
GeneralRe: Restrict window space for child process Pin
paulb23-Oct-03 12:56
paulb23-Oct-03 12:56 
Generalabout voice chat between a client and a server Pin
yingkou22-Oct-03 18:55
yingkou22-Oct-03 18:55 
Generalsimple questions.... Pin
joshfl22-Oct-03 18:09
joshfl22-Oct-03 18:09 
GeneralRe: simple questions.... Pin
abc87622-Oct-03 20:54
abc87622-Oct-03 20:54 
GeneralRe: simple questions.... Pin
David Crow23-Oct-03 4:03
David Crow23-Oct-03 4:03 
GeneralRe: simple questions.... Pin
joshfl23-Oct-03 6:05
joshfl23-Oct-03 6:05 
GeneralGet printer status by parallel port programming Pin
Rapo Lee22-Oct-03 17:48
Rapo Lee22-Oct-03 17:48 
GeneralHelp with a C bug Pin
Sirrius22-Oct-03 16:36
Sirrius22-Oct-03 16:36 
GeneralRe: Help with a C bug Pin
Anthony_Yio22-Oct-03 22:00
Anthony_Yio22-Oct-03 22:00 
GeneralRe: Help with a C bug Pin
David Crow23-Oct-03 4:06
David Crow23-Oct-03 4:06 
QuestionHow to make toolbar always active? Pin
Hailiang Yu22-Oct-03 16:17
Hailiang Yu22-Oct-03 16:17 
AnswerRe: How to make toolbar always active? Pin
Anthony_Yio22-Oct-03 21:43
Anthony_Yio22-Oct-03 21:43 
GeneralRe: How to make toolbar always active? Pin
Hailiang Yu22-Oct-03 23:42
Hailiang Yu22-Oct-03 23:42 
GeneralRe: How to make toolbar always active? Pin
Anthony_Yio27-Oct-03 16:13
Anthony_Yio27-Oct-03 16:13 
Generalrefreshing windows Pin
coda_x22-Oct-03 15:33
coda_x22-Oct-03 15:33 
GeneralRe: refreshing windows Pin
Atif Mushtaq22-Oct-03 21:58
Atif Mushtaq22-Oct-03 21:58 
GeneralRe: refreshing windows Pin
coda_x23-Oct-03 15:54
coda_x23-Oct-03 15:54 
GeneralHelp with random numbers... Pin
Snyp22-Oct-03 15:19
Snyp22-Oct-03 15:19 
GeneralRe: Help with random numbers... Pin
d00_ape23-Oct-03 1:50
sussd00_ape23-Oct-03 1:50 
GeneralRe: Help with random numbers... Pin
David Crow23-Oct-03 4:10
David Crow23-Oct-03 4:10 
QuestionI still have no idea how do we benefit from rescursion? Pin
Link260022-Oct-03 12:55
Link260022-Oct-03 12:55 
In the code below, the non-recursive version contains less
code than the recursive version one. And the non-recursive
version is also much clear than the recursive version.

We can always use loops to replace recursions, and besides,
many bugs are due to functions calling themselves.
I still have no idea how do we benefit from rescursion?
Can somesone please make an real world example of how do we
benefit from recursion?

Is recursion new addition to C++? Is there recursion in C?

Thanks.

// non recursive version
<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
   unsigned int num;<br />
   unsigned long fact = 1;<br />
<br />
   cout << "Please enter the n: ";<br />
   cin >> num;<br />
<br />
   for(int j = num; j > 0; --j)<br />
   {<br />
      fact *= j;<br />
   }<br />
<br />
   cout << "The factorial of n is: " << fact << "." << endl;<br />
<br />
   return 0;<br />
}<br />



// recursive version
<br />
#include <iostream><br />
using namespace std;<br />
<br />
unsigned long factfunc(unsigned long);<br />
<br />
int main()<br />
{<br />
   unsigned int num;<br />
   unsigned long fact = 1;<br />
<br />
   cout << "Please enter the n: ";<br />
   cin >> num;<br />
<br />
   fact = factfunc(num);<br />
   cout << "The factorial of n is: " << fact << "." << endl;<br />
<br />
   return 0;<br />
}<br />
<br />
unsigned long factfunc(unsigned long n)<br />
{<br />
   if(n >1)<br />
      return n * factfunc(n-1);<br />
   else <br />
      return 1;<br />
}<br />
<br />

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.