Algorithm to divide a given number in two proportions by one of the component of that number

Thanks @Ole V.V for the solution.I ran your code against below

double a = 10000;//can be 40,000,000
double n = 50000;//can b 5,000,000,000
double r = a * 100 / n;//should be between a given range

However ,in the output “r” is always constant(20.0)for each and every iteration
We actually need r between an given range and it should be different for [1] and [2].
Code should actually ONLY print n1,a1,r1 and n2,a2,r2 ,where “r” falls between the given range of “r”
For a bigger number of “a” and “r” , your code will throw out of memory.

Leave a Comment