Advertisement
Racknoss

Проверка парадокса дней рождений

Aug 20th, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iostream>
  3. #include <cmath>
  4. #include <cstdlib>
  5. #include <ctime>
  6.  
  7. using namespace ::std;
  8.  
  9. int Mass[23];
  10. bool van;
  11.  
  12. const int N(100);
  13.  
  14. bool proof(void)
  15. {
  16.     for (int akk(0); akk < N; akk++)
  17.     {
  18.         for (int akkk(N-1); akkk > akk; akkk--)
  19.         {
  20.             if (Mass[akk] == Mass[akkk]){ van = true; }
  21.         }
  22.     }
  23.     return van;
  24. }
  25.  
  26. int main(void)
  27. {
  28.     setlocale(LC_ALL, "Russian");
  29.     srand(time(NULL));
  30.     int algodlinn, protrue(0);
  31.     cout << "Сколько раз произвести вычисления? - ";
  32.     cin >> algodlinn;
  33.     for (short int i(0); i < algodlinn; i++)
  34.     {
  35.         system("cls");
  36.         for (int ak(0); ak < N; ak++)
  37.         {
  38.             Mass[ak] = rand() % 365;
  39.         }
  40.         for (int ak(0), akk(0); ak < N; ak++)
  41.         {
  42.             cout << Mass[ak] << "  ";
  43.             akk++;
  44.             akk = akk % 7;
  45.             if (akk == 6) cout << endl;
  46.         }
  47.         van = false;
  48.         if (proof() == true) protrue++;
  49.         cout << endl << ((double)i / (algodlinn-1)) * 100 << "%";
  50.         cout << endl << ((double)protrue / i) * 100 << "%";
  51.  
  52.  
  53.     }
  54.     cout << endl;
  55.     system("pause");
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement