Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- bool tarkistus (int tot, int draw) {
- if ( tot <= 0 or draw <= 0) {
- cout << "The number of balls must be a positive number." << endl;
- return false;
- }
- else if ( draw > tot ){
- cout << "The maximum number of drawn balls is the total amount of balls." << endl;
- return false;
- }
- else {
- return true;
- }
- }
- int mahdollisuuksia( int n, int p, int np)
- {
- int m = (n / (np * p));
- return m ;
- }
- unsigned long int factorial(int n)
- {
- if(n > 1)
- return n * factorial(n - 1);
- else
- return 1;
- }
- int main()
- {
- unsigned long int tot_amount = 0;
- cout << "Enter the total number of lottery balls: ";
- std::cin >> tot_amount;
- unsigned long int drawn = 0;
- cout << "Enter the number of drawn balls: ";
- std::cin >> drawn;
- if ( tarkistus(tot_amount, drawn) ) {
- int n = factorial(tot_amount);
- int p = factorial(drawn);
- int np = factorial(tot_amount - drawn);
- cout << "The probability of guessing all " << drawn << " balls correctly is 1/" << mahdollisuuksia(n, p, np) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement