Skip to content

Instantly share code, notes, and snippets.

Created February 21, 2013 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5001828 to your computer and use it in GitHub Desktop.
Save anonymous/5001828 to your computer and use it in GitHub Desktop.
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment