Greatest common divisor and least common multiple for two numbers

Source: Internet
Author: User

The greatest common divisor of two numbers (using the method of dividing the divide) and the least common multiple

Euclidean method:

1. First the remainder is obtained by using a small number in addition to the large number. number.

3. A third remainder is obtained with the second remainder, in addition to the first remainder.

This is followed by a successive number minus the previous remainder until the remainder is 0.

Program code:

#include <stdio.h>

int Main ()

{

int c = 0;

int a = +, B =-;

int ta = a, TB = b;

if (Ta > TB)

{

Ta = b;

TB = A;

}

c = Tb%ta;

while (c)

{

TB = TA;

Ta = c;

c = Tb%ta;

}

printf ( "greatest common divisor:%d\n" , TA);

printf ( "least common multiple:%d\n" , (a*b)/TA);

System ( "pause");

return 0;

}


Greatest common divisor and least common multiple for two numbers

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.