Sunday, October 12, 2008

Implementation of my division algorithm in C++

Hello guys, I have written a new approach (in C++) towards dividing two large numbers, input is dividend and divisor, and output shall be quotient and remainder. The algorithm and source code in C++ is presented here "as-is", anyone can use it, without any warranty to the damage(s) that may happen. The source code in text format is well documented and is self-explanatory.

ALGORITHM:
INPUT : Dividend, Divisor
OUTPUT: Quotient, Remainder
static int cnt;
if (dividend = divisor)
   return quotient = 0, remainder = 0
else if (dividend < divisor)   
return quotient = 0, remainder = dividend 
else  
{
   static int residue = dividend;  
   while(residue >= divisor)
{
residue = residue - divisor;
cnt++;
}
}
return quotient = cnt; remainder = residue;
The source code in C++ can be downloaded from HERE

No comments: