Division variable addition/subtraction and shift implementation: Test Subtraction

Source: Internet
Author: User

 

// 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 ");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.