Like Tree2Likes
  • 2 Post By grumpy

Arithmetic division

This is a discussion on Arithmetic division within the C Programming forums, part of the General Programming Boards category; Hi everyone. I need to create a program in C that given two integers numbers, i will divide both, for ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    7

    Arithmetic division

    Hi everyone.

    I need to create a program in C that given two integers numbers, i will divide both, for example, 1/3 = 0,333333..
    But i cant use double variables, i only can use integers.
    I need to divide two numbers how humans divide if dont have calculator, using denominator, quotient and rest.

    This is the first part of the problem, the second is...
    When i have the results of the divisions, i need to analyse all the results and see if the number have some part that repeats and a part that not repeats.
    Some like this:
    19/44 = 0.43181818
    Only the numbers at the right of the comma interest.
    Well, 43 dont repeat, we need that value for the non repeat value, and then we had a number that is repeating that is 181818, i need to save that value for another variable.

    and that is the problem.

    Can anyone give me some help with this problem? i need to have this problem finish until tomorrow, need some assistance with urgency.

    Thanks Community

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,266
    Quote Originally Posted by André Sousa View Post
    I need to create a program in C that given two integers numbers, i will divide both, for example, 1/3 = 0,333333..
    But i cant use double variables, i only can use integers.
    I need to divide two numbers how humans divide if dont have calculator, using denominator, quotient and rest.
    The technique you want is called "long division". It is an iterative technique, that keeps going until a specified end condition is met (no remainder to divide, specified number of significant figures reached, or a recurring pattern identified).

    Quote Originally Posted by André Sousa View Post
    When i have the results of the divisions, i need to analyse all the results and see if the number have some part that repeats and a part that not repeats.
    Some like this:
    19/44 = 0.43181818
    Only the numbers at the right of the comma interest.
    Well, 43 dont repeat, we need that value for the non repeat value, and then we had a number that is repeating that is 181818, i need to save that value for another variable.
    I assume the value you want to recover is "18" not "1818".

    When doing the long division, as I mentioned, two of the possible termination conditions are a zero remainder (in which case there is no recurring pattern) and recognising when a repeating pattern occurs (i.e. when the same sequence of operations is being performed again and again).

    I've given you pointers that are sufficient - with a bit of thought - for you to produce working code.
    iMalc and jwroblewski44 like this.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    7
    Quote Originally Posted by rags_to_riches View Post
    Lol who said i was asking the full program? i was asking for some tips and maybe links or other any type of functions that people already know that exists in the web and that i can stay with it soon.

    grumpy

    Thanks for the help i was watching some code in the web i found good things, the long division tip gave me some help

  5. #5
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    289
    Don't forget about solutions that "repeat".

    ie 10 / 3 = 3.33 repeated ( which would be represented mathematically with a line over the fractional portion, the 33 in this case ).

  6. #6
    Registered User
    Join Date
    Sep 2012
    Posts
    7
    Hi, sorry about the slow answer.
    I already have the code of the long division.
    Now i need to check when a number is repeating.
    like the exemple above.
    10/3 = 3.33333(3)

    i need to check that the number is repeating and i need to save that repeating number and the non repeating number.
    Some like: 9/44 = 0.43181818

    i need to save the 43 for the non repeating number and the 18 for the repeating number.
    Some tips about how can i do it?

    Thanks for all the answers, it was really helpful.

  7. #7
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    289

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    It's repeating if certain variables used in the loop have the same value that they did on the last iteration.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    Registered User
    Join Date
    Jun 2005
    Posts
    6,266
    Quote Originally Posted by iMalc View Post
    It's repeating if certain variables used in the loop have the same value that they did on the last iteration.
    That's only if a single digit is being repeated. If a pair of digits is being repeated, it is the values over two iterations that are repeated as a set. If n digits are being repeated, it is the values over n iterations that are repeated as a set.

    Incidentally, it is not actually necessary to do a long division to identify the non-repeating and repeating segments. There are certain mathematical relationships that can be exploited.....
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arithmetic
    By Ducky in forum C++ Programming
    Replies: 2
    Last Post: 05-02-2012, 09:45 AM
  2. Arithmetic Help
    By cduce2411 in forum C++ Programming
    Replies: 3
    Last Post: 03-18-2009, 11:58 AM
  3. arithmetic
    By shuo in forum C++ Programming
    Replies: 1
    Last Post: 01-20-2008, 04:29 PM
  4. arithmetic help
    By freeindy in forum C Programming
    Replies: 10
    Last Post: 09-18-2007, 08:01 AM
  5. Division by 0
    By ajaxthegreater in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-08-2005, 04:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21