Help me to know whether there are any processes in C++ by applying which I can find out whether the decimal representation of p/q
is a rational number or an irrational number.
For example 10/4 = 2.5
is a rational number where 10/3 = 3.3333333
is an irrational number
p/q is always a rational number by definition.
I think you meant whether decimal representation of p/q terminates or not, for that:
let d=q/gcd(p,q)
if d has only 2 and 5 as its prime factors, its decimal representation terminates, else it doesn't
But I also want to know if d has only 2 or only 5 as its prime factor then its decimal representation terminates or the number d should contain at least one 2 and one 5 in its prime factorization
d can have both 2 and 5 as its prime factors
the condition is: d should not have any other prime factor except 2 and 5
where can I read more about this? Is there a name for this?
umm, i know this from my mid/high school curriculum. so i dont know any reading materials.
i dont think there is a specific name for this, you can search it like:when is the decimal representation of a rational number terminating?
as i said in the original comment, ANY p/q is a rational number.
so, 10/3, 59/69, 69/435666828 all are rational numbers
......
some rational numbers have terminating decimals, for example 10/4=2.5 (terminating decimal)
some rational numbers have non-terminating but repeating decimals, for example 10/3=3.3333333333333.......
My final query
In your given example 10/4 has a terminating decimal because 4/gcd(10,4) has prime factor 2
and 10/3 does not have any prime factor 2 or 5. That is why it does not have any terminating decimal point.
Isn't it?
yes,
in 10/4, d=4/gcd(10,4)=4/2=2, d only has 2 as its prime factor. so decimal representation of 10/4 is terminating (2.5)
while in case of 10/3, d=3/gcd(10,3)=3/1=3, which has 3 as its prime factor (a number different from 2 and 5). So, its decimal representation is repeating (3.3333...)