M_A_Noman's blog

By M_A_Noman, 13 months ago, In English

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

  • Vote: I like it
  • -5
  • Vote: I do not like it

| Write comment?
»
13 months ago, # |
Rev. 2   Vote: I like it +30 Vote: I do not like it

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

  • »
    »
    13 months ago, # ^ |
    Rev. 4   Vote: I like it 0 Vote: I do not like it
    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

    • »
      »
      »
      13 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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

      • »
        »
        »
        »
        13 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        where can I read more about this? Is there a name for this?

        • »
          »
          »
          »
          »
          13 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          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?

      • »
        »
        »
        »
        13 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it
        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?
        
        • »
          »
          »
          »
          »
          13 months ago, # ^ |
            Vote: I like it +18 Vote: I do not like it

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

          • »
            »
            »
            »
            »
            »
            13 months ago, # ^ |
            Rev. 2   Vote: I like it 0 Vote: I do not like it

            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?

            • »
              »
              »
              »
              »
              »
              »
              13 months ago, # ^ |
                Vote: I like it 0 Vote: I do not like 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...)