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. 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. Originally Posted by André Sousa
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).

Originally Posted by André Sousa
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.

3. Originally Posted by rags_to_riches
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

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

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

6. It's repeating if certain variables used in the loop have the same value that they did on the last iteration.

7. Originally Posted by iMalc
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.....

Popular pages Recent additions