// From a book, we can see the division, addition, subtraction, and shift implementation, and share them.
// Calculate n/d, and D is the unsigned number. It is assumed that the quotient Q cannot exceed n digits.
// Division, division, addition, subtraction, and shift: Test Subtraction
Unsigned udiv_simple (unsigned D, unsigned N, unsigned N)
{
Unsigned q = 0, r = N;
Do {
N --;
If (r> N)> = D)
{
R-= (d <n );
Q + = (1 <n );
}
} While (N );
Return Q;
}
/****************** Just for test ***************** **********************/
# Include <stdio. h>
# Include <stdlib. h>
Int main (INT argc, char ** argv)
{
Int d, n;
Int result;
If (argc! = 3)
{
Printf ("wrong usage! \ R \ nexample:./A. out 5 33 \ r \ n ");
Return 1;
}
D = atoi (argv [1]);
N = atoi (argv [2]);
Result = udiv_simple (d, n, 31 );
Printf ("% d \ n", result );
// Printf ("Hello world! \ N ");
// System ("pause ");
}