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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include <iostream>
#include <cmath>
#include<string>
using namespace std;
double Factoriel(double t)
{
double x(0.0);
for(int i = 1; i <=t; ++i)
{
x *= i;
}
return q;
}
double Binomfdp(int n,double p, int q)
{
return ((Factoriel(n)) / (Factoriel(q) * Factoriel(n-q))) * pow(p,q) * pow(1-p,n-q);
}
double Binomfrep(int n, double p , int k)
{
double l(0.0);
for (int compteur(0); compteur < k+1; compteur++ )
{
l = l + Binomfdp(n,p,compteur);
}
return l;
}
int main()
{
int nombre;
bool partie;
string reponse;
double prob;
double k, m;
do
{
cout << "Quel est le nombre d'essaie?" << endl;
cin >> nombre;
cout << "Quel est la probabilité du succes?" << endl;
cin >> prob;
k = 0;
m = 0;
while (Binomfrep(nombre, prob, k) <= 0.025)
{
k = k + 1;
}
cout << "A=" << k << endl;
while (Binomfrep(nombre,prob, m) < 0.975)
{
m = m + 1;
}
cout << "B=" << m << endl;
cout << Binomfdp(nombre,prob,5) << endl;
cout << Binomfrep(nombre,prob,5) <<endl;
cout << " On refais une partie? (O/N)" << endl;
cin >> reponse;
if (reponse == "O")
{
partie = true;
}
else
{
partie = false;
}
}while (partie);
return 0;
} |
Partager