### M_A_Noman's blog

By M_A_Noman, 10 months ago,

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

• -5

 » 10 months ago, # | ← Rev. 2 →   +30 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
•  » » 10 months ago, # ^ | ← Rev. 4 →   0 Thanks, brother I actually want to know that. 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
•  » » » 10 months ago, # ^ |   0 d can have both 2 and 5 as its prime factorsthe condition is: d should not have any other prime factor except 2 and 5
•  » » » » 10 months ago, # ^ |   0 where can I read more about this? Is there a name for this?
•  » » » » » 10 months ago, # ^ |   0 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?
•  » » » » 10 months ago, # ^ |   0 Let me explain my confusion  let p = 10 and q = 4 then gcd(p,q)=2 d = q/gcd(p,q)=2 d has prime factor 2 so this p/q is a rational number am I right? 
•  » » » » » 10 months ago, # ^ |   +18 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.......
•  » » » » » » 10 months ago, # ^ | ← Rev. 2 →   0 My final query In your given example 10/4 has a terminating decimal because 4/gcd(10,4) has prime factor 2and 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?
•  » » » » » » » 10 months ago, # ^ |   0 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...)
•  » » » » » » » » 10 months ago, # ^ |   0 Thank you very much brother for your kind information