GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Jul-2005, 08:03
tgtg tgtg is offline
New Member
 
Join Date: Jul 2005
Posts: 1
tgtg is on a distinguished road

base case clarification


Trying to figure out how many base cases the following code has. I believe this is still just one. If my thinking is correct ,it would be two if m== something and n== something and the general case was and if else. A little confused.

CPP / C++ / C Code:
int func1(intm, int n) { 
if (m==n ||n==1)                                           // base case
return1; 
else 
return func1(m-1,n-1) + n*func1(m-1,n);          //general case
}
Last edited by LuciWiz : 20-Jul-2005 at 08:07. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 20-Jul-2005, 08:23
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough
To figure this out, try to break up the or-condition and rewrite this function without it, using only if-else-if.
CPP / C++ / C Code:
int func1(int m, int n)
{
  if (m == n)                                          // first base case
    return 1;
  else if (n == 1)                                     // second base case
    return 1;
  else
    return func1(m - 1, n - 1) + n * func1(m - 1, n);  //general case
}

Matthew
 
 

Recent GIDBlogToyota - 2008 August Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with one variable bretter C++ Forum 1 16-May-2005 07:20
Compiling Errors ToddSAFM C++ Forum 22 18-Dec-2004 11:42
Problems with switch statement dontcare C++ Forum 4 29-Nov-2004 18:28
there has to be a better way dabigmooish C++ Forum 8 17-May-2004 10:24
C++ file I/O CronoX C++ Forum 36 09-Mar-2004 17:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:42.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.