C语言求最大公约数和最小公倍数算法

2015-01-21 11:07:57 · 作者: · 浏览: 41


其算法过程为:前提:设两数为a,b设其中a 做被除数,b做除数,temp为余数

1、大数放a中、小数放b中;

2、求a/b的余数;

3、若temp=0则b为最大公约数;

4、如果temp!=0则把b的值给a、temp的值给b;

5、返回第第二步;

#include 
  
   
#include 
   
     void main(){ int divisor(int a,int b); int multiple(int a,int b); printf("The highest common divisor is %d \n",divisor(15,9)); printf("The lowest common multiple is %d \n",multiple(15,9)); } int divisor(int a,int b){ int temp; if(a