Problem Description
Enter two integers to ask for their greatest common divisor and least common multiple.
Input
An integer of two.
Output
Greatest common divisor and least common multiple.
Sample Input
12 9
Sample Output
3 36
HINT
The minimum number of conventions and least common multiple can be written as functions to facilitate later invocation.
1#include <stdio.h>2 3 voidMain ()4 5 {6 7 intM,n;8 9 while(SCANF ("%d%d", &m,&n)! =EOF)Ten One { A - if(m>N) - the { - - for(intI=m;; i--) - + { - + if((m%i==0) && (n%i==0)) A at { - -printf"%d%d\n", i,m*n/i); - - Break; - in } - to } + - } the * Else $ Panax Notoginseng { - the for(intI=n;; i--) + A { the + if((m%i==0) && (n%i==0)) - $ { $ -printf"%d%d\n", i,m*n/i); - the Break; - Wuyi } the - } Wu - } About $ } - -}
Other code:
1#include <stdio.h>2#include <math.h>3 intgcdintAintb)4 {5 if(a%b==0)6 returnb;7 Else8 returnGCD (b,a%b);9 }Ten intLcmintAintb) One { A returna*b/gcd (A, b); - } - intMain () the { - intb; - while(~SCANF ("%d%d",&a,&b)) - { +printf"%d%d\n", gcd (A, B), LCM (A, b)); - } + return 0; A}
Wuhan University of Science and Technology acm:1007: Chinese Edition C language Programming tutorial (second Edition) example 4.13