home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Reflector / CS / Factorial.cs next >
Encoding:
Text File  |  2000-06-23  |  1.7 KB  |  56 lines

  1. /*+==========================================================================
  2.   File:      Factorial.cool
  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 COM+ 2.0 SDK Samples
  14.  
  15.   Copyright (C) 1998-1999 Microsoft Corporation.  All rights reserved.
  16. ==========================================================================+*/
  17.  
  18. using System;
  19.  
  20. class Factorial
  21. {
  22. /*****************************************************************************
  23.  Function :    Value
  24.  
  25.  Abstract:     Computes the Factorial of the input (printing information to 
  26.                standard output.
  27.             
  28.  Input Parameters: i (the number to compute the factorial of)
  29.  
  30.  Returns: int
  31. ******************************************************************************/
  32.     public int Value(int i)
  33.     { 
  34.         Console.Write("Factorial::Value:");
  35.         Console.WriteLine(i);
  36.         int ret = calc(i);
  37.         Console.Write("Factorial::Value returning:");
  38.         Console.WriteLine(ret);
  39.         return ret;
  40.     }
  41.  
  42. /*****************************************************************************
  43.  Function :    calc
  44.  
  45.  Abstract:     Computes the Factorial of the input.
  46.             
  47.  Input Parameters: i (the number to compute the factorial of)
  48.  
  49.  Returns: int
  50. ******************************************************************************/
  51.     public int calc(int i)
  52.     {
  53.         return((i <= 1) ? 1 : (i * calc(i-1)));
  54.     }
  55. };
  56.