Maximizing Probability of one type from N containers | CPP program to find maximum probability of getting a copy ' A ' from N ; Returns the Maximum probability for Drawing 1 copy of number A from N containers with N copies each of numbers A and B ; Pmax = N / ( N + 1 ) ; Driver code ; 1. N = 1 ; 2. N = 2 ; 3. N = 10
#include <bits/stdc++.h> NEW_LINE using namespace std ; double calculateProbability ( int N ) { double probability = ( double ) N / ( N + 1 ) ; return probability ; } int main ( ) { int N ; double probabilityMax ; N = 1 ; probabilityMax = calculateProbability ( N ) ; cout << " Maximum ▁ Probability ▁ for ▁ N ▁ = ▁ " << N << " ▁ is , ▁ " << setprecision ( 4 ) << fixed << probabilityMax << endl ; N = 2 ; probabilityMax = calculateProbability ( N ) ; cout << " Maximum ▁ Probability ▁ for ▁ N ▁ = ▁ " << N << " ▁ is , ▁ " << setprecision ( 4 ) << fixed << probabilityMax << endl ; N = 10 ; probabilityMax = calculateProbability ( N ) ; cout << " Maximum ▁ Probability ▁ for ▁ N ▁ = ▁ " << N << " ▁ is , ▁ " << setprecision ( 4 ) << fixed << probabilityMax << endl ; return 0 ; }