最大公约数 和 最小公倍数

 

 1 #include <stdio.h>
 2 
 3 int iGcd(int iU, int iV)
 4 {
 5     int iRemainder = iU%iV;
 6     while(iRemainder != 0)
 7     {
 8         iU = iV;
 9         iV = iRemainder;
10         iRemainder = iU%iV;
11     }
12     return iV;
13 }
14 
15 int iLcm(int iU, int iV)
16 {
17     return (iU*iV)/iGcd(iU, iV);
18 }
19 
20 int main()
21 {
22     printf("%d %d\n", iGcd(6, 4), iLcm(6, 4));
23     return 0;
24 }

 

posted @ 2014-12-01 19:04  MDGSF  阅读(102)  评论(0)    收藏  举报