UMBC CS 201, Fall 98
UMBC CMSC 201 & 201H Fall '98 CSEE | 201 | 201 F'98 | lectures | news | help

Examples

Example: Countdown

void Countdown (int k) 
{
   if (k == 0) 
   {
      printf("KABOOM!!!\n") ;
   } 
   else 
   {
      printf("   %d seconds to auto-destruct\n", k);
      Countdown (k - 1) ;
   }
}

Example: Factorial

int Factorial (int n)
{
   if (n == 0) 
   {
      return (1);
   }
   else 
   {
      return (n * Factorial (n - 1)));
   }
}

Example: Multiply

int Mul( int a, int b) 
{
   if (b == 1) 
   {
      return( a);
   }
      else 
   {
      return (a + Mul (a, b - 1)));
   }
}





CSEE | 201 | 201 F'98 | lectures | news | help

Sunday, 06-Dec-1998 18:02:37 EST