Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members Related Pages Search
fungmath.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "fungmath.h"
00018
00019 #include <cmath>
00020 #include <ctime>
00021 #include <cstdlib>
00022
00023 int num_digits( int i )
00024 {
00025 int n = i / 10;
00026 if ( n == 0 )
00027 return 1;
00028 else
00029 return num_digits( n );
00030
00031 }
00032
00033 int fibonacci( unsigned int n )
00034 {
00035 if ( n == 0)
00036 return 0;
00037 else if ( n == 1 )
00038 return 1;
00039 else
00040 return fibonacci( n - 1 ) + fibonacci( n - 2 );
00041 }
00042
00043 int factorial( unsigned int n )
00044 {
00045 if ( n == 0 )
00046 return 1;
00047 else
00048 return factorial( n - 1 ) * n;
00049 }
00050
00051 int iRand( float low, float high )
00052 {
00053 return (rand() % static_cast<int>(ROUND(high-low-1)))+static_cast<int>(ROUND(low)) + 1;
00054 }
00055
00056 float fRand( float low, float high )
00057 {
00058 return static_cast<float>(rand())/static_cast<float>(RAND_MAX) * (high-low) + low;
00059 }
00060
00061
00062
|