public
anonymous / gist:5001828
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include <iostream>
#include <cmath>
using namespace std;
 
int main()
{
int ntrials,i, t1, t2, t3, t4, t5;
int numHeads = 0;
double headsPercent;
 
 
cout << " Enter Number of 5-Toss Trials : " <<endl;
cin >> ntrials;
 
 
for(i = 0; i < ntrials; i++ )
{
t1 = rand() % 2;
t2 = rand() % 2;
t3 = rand() % 2;
t4 = rand() % 2;
t5 = rand() % 2;
if( t1 == 0 && t2 == 0 && t3 == 0 && t4 == 0 && t5 == 0) numHeads++;
}
 
cout <<" Number of Trials resulting in 5/5 Heads: " << numHeads <<endl;
 
headsPercent = 100 * ( (double)numHeads / ntrials);
 
cout << " 5/5 Heads Trial Percentage: " << headsPercent << " %"<<endl;
 
system ("pause");
return 0;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.