// 求两个数m和n的最大公约数(辗转相除法) #include <stdio.h> int yue( int x, int y ) { int temp; int tem; // 保证分母不为0 if( y == 0 ) { x = temp; temp = y; y = x; } // 辗转相除法 while( tem ) { tem = x % y; x = y; y = tem; } return x; } int main() { int a,b; printf("请输入要求的两个数:"); scanf("%d%d",&a,&b); printf("最大公约数是:%d\n",yue( a,b )); return 0; } <img src="http://img.blog.csdn.net/20150423115407950?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
时间: 2024-10-05 04:55:52