Created
February 21, 2013 03:35
-
-
Save anonymous/5001828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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