U have a function which takes two nos a and b as int inputs and returns an int sum, give the probability that this function fails, given no float and decimal are passed to the function and int can take values from 0 to UImax.
Sigiloso
The function will fail only when the sum of the two nos is greater than UImax, so the no of ways it can fail is as follows: when a=0, no chance of error a=1, there will be one error for b = UImax a=2, there will be two cases for which it fails and they being b=UImax, UImax-1 so in general when a=n, it fails for n inputs of b totally when we add up the possibility of error turns out to be UImax(UImax + 1)/2 total no of ways the function can be called is (UImax)^2 therefore, the probability of the function failing is given by: UImax(UImax + 1)/2/(UImax)^2, when UImax is very large, (UImax + 1) ~ UImax therefore probability turns out to be 1/2.