C language for two numbers of greatest common divisor and least common multiple

Source: Internet
Author: User
Tags greatest common divisor

#include <stdio.h>

int main ()

{

Two number of greatest common divisor: greatest common divisor is the largest number of public between the two, we can first find the two number of the relatively small number;

int NUM1, num2, Gys, GBS;

scanf ("%d,%d", &num1, &num2);

int ji = NUM2*NUM1;

if (num1>num2) {//Find two number smaller number

int temp;

temp = NUM1;

NUM1 = num2;

num2 = temp; Interact with these two numbers to ensure that the NUM1 is the smallest number

}

for (int i = NUM1; i>0; i--) {

The number of two number of simultaneous satisfies divided by the largest can be greatest common divisor

if (num1%i = = 0 && num2%i = = 0) {

Gys = i; Greatest common divisor

Break

}

}

GBS = Ji/gys; least common multiple = the product of two numbers divided by greatest common divisor

printf ("Number of conventions:%d, common multiple:%d\n", Gys, GBS);

return 0;

}

C language for two numbers of greatest common divisor and least common multiple

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.