Advertisement
Aveneid

Untitled

Nov 7th, 2017
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int los_1,los_2,n,m,licznik;
  11. double p,licz=0;
  12.  
  13. do{
  14. cout<<"Podaj liczbe kostek: "<<endl;
  15. cin>>n;
  16. }while(n<=1);
  17. cout<<"Podaj liczbe oczek na kostce: "<<endl;
  18. cin>>m;
  19.  
  20. srand(time(NULL));
  21. for(int i=1;i<=n;i++)
  22. {
  23. los_1=rand()%m+1;
  24. for(int j=0;j<m;j++)
  25. {
  26. los_2=rand()%m+1;
  27. if(los_2!=los_1){
  28. cout<<"m"<<endl;break;}
  29. else{ licz++; cout<<"t"<<endl;}
  30. }
  31. }
  32. p=licz/(double)n;
  33. cout<<"Prawdopodobienstwo wynosi: "<<p<<endl;
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement