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

C / C++ / MFC

 
AnswerRe: embedding resource inside win32 dll Pin
Waldermort17-Feb-06 18:57
Waldermort17-Feb-06 18:57 
AnswerRe: embedding resource inside win32 dll Pin
Gavin Taylor19-Feb-06 2:41
professionalGavin Taylor19-Feb-06 2:41 
QuestionRandom move Pin
eivanlo17-Feb-06 16:41
eivanlo17-Feb-06 16:41 
AnswerRe: Random move Pin
_AnsHUMAN_ 17-Feb-06 17:22
_AnsHUMAN_ 17-Feb-06 17:22 
QuestionQuestion about recursion Pin
ericelysia17-Feb-06 15:35
ericelysia17-Feb-06 15:35 
AnswerRe: Question about recursion Pin
Michael Dunn17-Feb-06 16:22
sitebuilderMichael Dunn17-Feb-06 16:22 
GeneralRe: Question about recursion Pin
ericelysia17-Feb-06 16:36
ericelysia17-Feb-06 16:36 
GeneralRe: Question about recursion Pin
ericelysia17-Feb-06 18:54
ericelysia17-Feb-06 18:54 
OK, I still don't get it. I changed the code a little to make the invocations easier to see.

<br />
#include <iostream><br />
#include <iomanip><br />
using namespace std;<br />
<br />
unsigned long factorial( unsigned long ); // function prototype<br />
//-------------------------------------------------------------------------<br />
int count = 0;<br />
<br />
int main()<br />
{  <br />
   // Loop 2 times. During each iteration, calculate factorial( i ) and display result.<br />
   for ( int i = 0; i <= 2; i++ )<br />
   {<br />
	  cout << "\n i = " << i << endl;<br />
	  cout << endl << setw( 2 ) << i << "! = " << factorial( i ) << endl;<br />
	  cout << endl << "--------------------------------------------" << endl;<br />
   }<br />
   return 0;  // indicates successful termination<br />
<br />
} // end main<br />
//-------------------------------------------------------------------------<br />
// recursive definition of function factorial<br />
unsigned long factorial( unsigned long number )<br />
{  <br />
   count++;<br />
   cout << endl << "factorial was invoked for the " << count << " time "<br />
        << "   number = " << number << endl;<br />
<br />
   // base case<br />
   if ( number <= 1 )  <br />
   {<br />
	  cout << endl << "number <= 1" << endl;<br />
      return 1;<br />
   }<br />
   // recursive step<br />
   else  <br />
   {<br />
	  cout << endl << "number = " << number <br />
		   << "    factorial(number - 1) = " << factorial(number - 1) <br />
		   << "     " <br />
		   << number  << " * " << factorial( number - 1 ) << " = " <br />
		   << number * factorial( number - 1 ) << endl;    <br />
		         <br />
      return number * factorial( number - 1 );<br />
   }<br />
} // end function factorial<br />
//-------------------------------------------------------------------------<br />

OUTPUT:
<br />
<br />
 i = 0<br />
<br />
factorial was invoked for the 1 time    number = 0<br />
<br />
number <= 1<br />
<br />
 0! = 1<br />
<br />
--------------------------------------------<br />
<br />
 i = 1<br />
<br />
factorial was invoked for the 2 time    number = 1<br />
<br />
number <= 1<br />
<br />
 1! = 1<br />
<br />
--------------------------------------------<br />
<br />
 i = 2<br />
<br />
factorial was invoked for the 3 time    number = 2<br />
<br />
factorial was invoked for the 4 time    number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 5 time    number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 6 time    number = 1<br />
<br />
number <= 1<br />
<br />
number = 2    factorial(number - 1) = 1     2 * 1 = 2<br />
<br />
factorial was invoked for the 7 time    number = 1<br />
<br />
number <= 1<br />
<br />
 2! = 2<br />
<br />
--------------------------------------------<br />
Press any key to continue<br />
*/<br />


Please walk me through the following:
<br />
 i = 2<br />
<br />
factorial was invoked for the 3 time    number = 2<br />
<br />
factorial was invoked for the 4 time    number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 5 time    number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 6 time    number = 1<br />
<br />
number <= 1<br />
<br />
number = 2    factorial(number - 1) = 1     2 * 1 = 2<br />
<br />
factorial was invoked for the 7 time    number = 1<br />
<br />
number <= 1<br />
<br />
 2! = 2<br />


Thanks!
AnswerRe: Question about recursion Pin
David Crow18-Feb-06 7:13
David Crow18-Feb-06 7:13 
AnswerRe: Question about recursion Pin
Jeremy Thornton18-Feb-06 9:10
Jeremy Thornton18-Feb-06 9:10 
AnswerRe: Question about recursion Pin
ericelysia20-Feb-06 3:37
ericelysia20-Feb-06 3:37 
QuestionWinInet FtpPutFile Pin
rbrad1234517-Feb-06 15:21
rbrad1234517-Feb-06 15:21 
AnswerRe: WinInet FtpPutFile Pin
Michael Dunn17-Feb-06 15:53
sitebuilderMichael Dunn17-Feb-06 15:53 
GeneralRe: WinInet FtpPutFile Pin
rbrad1234518-Feb-06 16:48
rbrad1234518-Feb-06 16:48 
QuestionMFC42UD.lib Pin
super17-Feb-06 13:56
professionalsuper17-Feb-06 13:56 
AnswerRe: MFC42UD.lib Pin
super17-Feb-06 14:04
professionalsuper17-Feb-06 14:04 
QuestionReading file with X/Y axes? Pin
Lord Kixdemp17-Feb-06 13:20
Lord Kixdemp17-Feb-06 13:20 
AnswerRe: Reading file with X/Y axes? Pin
Lord Kixdemp17-Feb-06 15:40
Lord Kixdemp17-Feb-06 15:40 
Question[registry] get all values in a key Pin
Sam 200617-Feb-06 12:42
Sam 200617-Feb-06 12:42 
AnswerRe: [registry] get all values in a key Pin
Michael Dunn17-Feb-06 15:54
sitebuilderMichael Dunn17-Feb-06 15:54 
GeneralRe: [registry] get all values in a key Pin
Sam 200618-Feb-06 4:55
Sam 200618-Feb-06 4:55 
AnswerRe: [registry] get all values in a key Pin
Ganesh_T18-Feb-06 1:40
Ganesh_T18-Feb-06 1:40 
GeneralRe: [registry] get all values in a key Pin
Sam 200618-Feb-06 5:26
Sam 200618-Feb-06 5:26 
QuestionHow include extern DLL's as static Library into project? Pin
@LX17-Feb-06 12:42
@LX17-Feb-06 12:42 
AnswerRe: How include extern DLL's as static Library into project? Pin
John M. Drescher17-Feb-06 13:29
John M. Drescher17-Feb-06 13:29 

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.