viewing paste coinToss | C++

Posted on the
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
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
 
void coinToss(int A[], int n){
    
    for(int i = 0; i < n; i++)
        A[rand() % 100]++;
    
}
void showProb(const int C[], int n, int trials){
    int s,e;
    double p;
    for(s = 0; C[s] == 0; s++);
    for(e = n; C[e] == 0; e--);
    for(int i=s; i <=e; i++){
        p = double(C[i])/double(trials);
        std::cout << "Prob(H=" << i << ")" << p << std::endl;
    }
}
 
int main () {
    int n;
    srand(time(0));
    std::cout << "Number of coins to toss: ";
    std::cin >> n;
    int* Array = new int[100];
    coinToss(Array,n);
    showProb(Array, n, 1);
    
    return 0;
}
 
Viewed 1213 times, submitted by Streusel.