Parsing: Seeking gcd "principle of Euclidean division method"

Source: Internet
Author: User
Tags gcd
	Title: Enter two positive integers m and n, and ask for their gcd and LCM.
In c language code as follows:
	#include <stdio.h>
void Main ()
	int p, r, N, M, temp;
	printf ("Please enter two positive integers:");
	scanf ("%d,%d", &n, &m);
	if (n < m)
		temp = n;
		n = m;
		m = temp;
	p = n*m;
	while (M!= 0)
		r = n%m;
		n = m;
		m = r;
	printf ("Their gcd is:%d\n", n);
	printf ("Their LCM is:%d\n", n);
This uses the Euclidean method, the principle of the Euclidean method is as follows:
	The gcd of two integers is the largest positive integer that can divide them at the same time. The Euclidean method is based on the principle that the gcd of two integers equals the gcd of the smaller number and the difference of two numbers. For example, the GCD of 252 and 105 is 252 = 21x12;105 = 21x5), because 252−105 = 147, so the GCD of 147 and 105 is 21. In this process, the larger number shrinks, so the same calculation continues to shrink the two numbers until one of them becomes 0. At this point, the remaining not to zero is the number of two gcd.
Note: LCM equals two number of product divided by minimum Convention number

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: 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.