Recursion and Basic Multiplication

This is something I hadn’t considered as a way to have the additive effect of multiplication:

int Multiply( int X, int Y ){
  if ( X == 0 || Y == 0 )
    return 0;
  if ( X == 1 )
    return Y;
  if ( Y == 1 )
    return X;
  return Y + Multiply( X - 1, Y );
}

via here

0 Comments

Add Yours →

Leave a Reply