Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

fact.C

Go to the documentation of this file.
00001 // Factorial using sints
00002 // by Owen Astrachan
00003 
00004 #include "sint.h"
00005 #include <iostream.h>
00006 #include <stdlib.h>        // for atoi
00007 
00008 // illustrates use of sint class
00009     
00010 // precondition: n >= 0
00011 // postcondition: returns n!     
00012 sint Fact(int n) {
00013     sint prod;
00014     prod = 1;
00015     int k;
00016     for(k=1; k <= n; k++)
00017     {
00018         prod *= k;
00019     }
00020     return prod;
00021 }
00022 
00023 #ifdef TOOLBOX
00024 
00025 main(int argc, char * argv[])
00026 {
00027     int k;
00028     int limit;
00029     sint val;
00030 
00031     if (argc > 1){              // command line args?
00032         limit = atoi(argv[1]);
00033     }
00034     else{
00035         cout << "enter limit ";
00036         cin >> limit;
00037     }
00038 
00039     cout << "number \t factorial" << endl;
00040     cout << "------ \t ---------" << endl << endl;
00041     for(k=limit; k >= 1; k--)
00042     {
00043         val = Fact(k);
00044         cout << k << "\t" << val << "\t" << endl;
00045     }
00046     
00047     return 0;
00048 }
00049 
00050 #endif

Generated at Sun Feb 24 09:57:00 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001