fork download
  1. #include <ctime>
  2. #include <iostream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. srand(time(0));
  10.  
  11. const unsigned max = 10000;
  12. unsigned counter[10] = {0};
  13. for(unsigned i = 0; i < max; ++i)
  14. {
  15. ++counter[rand() % 10];
  16. }
  17. cout << "Zufallszahlen Wahrscheinlichkeitsberechner (von 1-10):\n\n";
  18. cout << "Zaehler: " << max << "\n\n";
  19. for (unsigned i = 0; i < 10; ++i)
  20. cout << "Zahl " << i + 1 << ": " << counter[i] << " = " << 1.*counter[i]/max*100 << "%\n";
  21. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Zufallszahlen Wahrscheinlichkeitsberechner (von 1-10):

Zaehler: 10000

Zahl 1: 991 = 9.91%
Zahl 2: 1047 = 10.47%
Zahl 3: 987 = 9.87%
Zahl 4: 1005 = 10.05%
Zahl 5: 997 = 9.97%
Zahl 6: 948 = 9.48%
Zahl 7: 1032 = 10.32%
Zahl 8: 968 = 9.68%
Zahl 9: 996 = 9.96%
Zahl 10: 1029 = 10.29%