Divide 2 big numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Divide 2 big numbers

I was wondering how to divide 2 huge numbers. Can you please help me? I am working in c++, and I am looking for an alorithm that divides 2 huge numbers using its digits. I read those numbers in 2 arrays. Thank you :)

19th Jan 2018, 4:16 PM
Stefan Secrieru
Stefan Secrieru - avatar
2 Answers
+ 1
With or without decimals?
20th Jan 2018, 1:42 AM
Jacob Pembleton
Jacob Pembleton - avatar
0
For an integer result division (When the return type is also an array), what I did was: From the start of the dividend, extract a number that is just greater than the divisor. Then find the highest multiple of the divisor just smaller than the extracted divisor. Then subtract the extracted dividend from the multiple of the divisor and assign it to the remainder. Then, if the remainder is smaller than the divisor,check if any digits are left in the left over dividend, plug the extra digits as per requirement, and restart the process with this modified remainder after each operation. Also, after every iteration, the result will get the quotient digit after division, which is the number we multiplied the divisor with earlier. Then in the end, when the final remainder is 0 or smaller than the divisor and you will not have any more digits to extract from the main dividend, the division is complete. I am sure this is not the best method to do things, as it separately requires you to get a subtraction function. Also, you may check my code, though you may find it shabby. https://code.sololearn.com/cTeO3C6896xL/?ref=app
20th Jan 2018, 3:50 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar