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  and .
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.