home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Reflector / VC / Factorial.cpp next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  1.7 KB  |  58 lines

  1. /*+==========================================================================
  2.   File:      Factorial.cpp
  3.  
  4.   Summary:   Computes the factorial of a number (the Value method should be
  5.              the entry point).  This class is present to provide a class
  6.              to test with the Reflector sample.
  7.  
  8.   Classes:   Factorial
  9.  
  10.   Functions: Value, calc
  11.  
  12. ----------------------------------------------------------------------------
  13.   This file is part of the Microsoft NGWS Samples.
  14.  
  15.   Copyright (C) 1998-2000 Microsoft Corporation.  All rights reserved.
  16. ==========================================================================+*/
  17.  
  18. #using <mscorlib.dll>
  19. using namespace System;
  20.  
  21. __gc public class Factorial
  22. {
  23. public:
  24. /*****************************************************************************
  25.  Function :    Value
  26.  
  27.  Abstract:     Computes the Factorial of the input (printing information to 
  28.                standard output.
  29.             
  30.  Input Parameters: i (the number to compute the factorial of)
  31.  
  32.  Returns: int
  33. ******************************************************************************/
  34.     int Value(int i)
  35.     { 
  36.         Console::Write(L"Factorial::Value:");
  37.         Console::WriteLine(i);
  38.         int ret = calc(i);
  39.         Console::Write(L"Factorial::Value returning:");
  40.         Console::WriteLine(ret);
  41.         return ret;
  42.     }
  43.  
  44. /*****************************************************************************
  45.  Function :    calc
  46.  
  47.  Abstract:     Computes the Factorial of the input.
  48.             
  49.  Input Parameters: i (the number to compute the factorial of)
  50.  
  51.  Returns: int
  52. ******************************************************************************/
  53.     int calc(int i)
  54.     {
  55.         return((i <= 1) ? 1 : (i * calc(i-1)));
  56.     }
  57. };
  58.