Блог пользователя M_A_Noman

Автор M_A_Noman, 3 года назад, По-английски

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
  • Проголосовать: не нравится

»
3 года назад, скрыть # |
← 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