Home › Forums › C Programming › coin toss › Re: Re: coin toss
heres a simpler version ( no driver function ). Seems to work fine – needs to be tested….
/****************************************************************
* File Name : c:programshelppermutations.cpp
* Date : August,1,2002
* Comments : new project
* Compiler/Assembler :
*
*
*
*
*
* Program Shell Generated At: 5:59:12 p.m.
=-=-=-=-=-=-=-=–=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
#include < iostream >
//#include < string.h >
//#include < conio.h >
//#include < math.h >
//#include < iomanip >
//#include < ctype.h >
using namespace std;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@
void coinPermutations ( int flips , char * permutations );
//##################################################################################
//main function ******************************
int main ( )
{
int numberOfFlips;
cout << "enter number of flips: ";
cin >> numberOfFlips;
cout << "permutations: " << endl;
char * permutations = new char [ numberOfFlips + 1 ];
permutations [ numberOfFlips ] = 0;
coinPermutations ( numberOfFlips – 1 , permutations );
delete [] permutations;
return 0 ;
}
/******************************* FUNCTION DEFINITION ******************************
Name : coinPermutatins
Parameters :
face a(n) char
Returns: Void type
Comments:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void coinPermutations ( int flips , char * permutations )
{
if ( flips == 0 )
{
permutations [ flips ] = ‘t’;
cout << permutations << endl;
permutations [ flips ] = ‘h’;
cout << permutations << endl;
return;
}
permutations [ flips ] = ‘t’;
coinPermutations ( flips – 1 , permutations ) ;
permutations [ flips ] = ‘h’;
coinPermutations ( flips – 1 , permutations );
return;
}