home *** CD-ROM | disk | FTP | other *** search
- /*+==========================================================================
- File: Factorial.cpp
-
- Summary: Computes the factorial of a number (the Value method should be
- the entry point). This class is present to provide a class
- to test with the Reflector sample.
-
- Classes: Factorial
-
- Functions: Value, calc
-
- ----------------------------------------------------------------------------
- This file is part of the Microsoft NGWS Samples.
-
- Copyright (C) 1998-2000 Microsoft Corporation. All rights reserved.
- ==========================================================================+*/
-
- #using <mscorlib.dll>
- using namespace System;
-
- __gc public class Factorial
- {
- public:
- /*****************************************************************************
- Function : Value
-
- Abstract: Computes the Factorial of the input (printing information to
- standard output.
-
- Input Parameters: i (the number to compute the factorial of)
-
- Returns: int
- ******************************************************************************/
- int Value(int i)
- {
- Console::Write(L"Factorial::Value:");
- Console::WriteLine(i);
- int ret = calc(i);
- Console::Write(L"Factorial::Value returning:");
- Console::WriteLine(ret);
- return ret;
- }
-
- /*****************************************************************************
- Function : calc
-
- Abstract: Computes the Factorial of the input.
-
- Input Parameters: i (the number to compute the factorial of)
-
- Returns: int
- ******************************************************************************/
- int calc(int i)
- {
- return((i <= 1) ? 1 : (i * calc(i-1)));
- }
- };
-