View Code of Problem 59

#include<stdio.h>

find_max(int a,int b){
	int temp;
	temp = a%b;
	if(temp==0)return b;
	else{
		a = b;
		b= temp;
		find_max(a,b);
	}
}
find_max1(int a,int b){
	int temp,i;
	if(a>b){
		temp = a ;
		a = b ;
		b = temp;
	}
	for(i=a;i>0;i--){
		if(a%i==0&&b%i==0)break; 
	}
	return i;
}
find_min(int a,int b){
	int temp,i;
	if(a<b){
		temp = a;
		a = b ;
		b = temp;
	}
	for(i=a;i<=a*b;i++){
		if(i%a==0&&i%b==0)
			break;
	}
	return i ;
}
int main(){
	int a ,b;
	int max,min;
	printf("请输入2个整数"); 
	scanf("%d %d",&a,&b);
	max = find_max1(a,b);//max = find_max(a,b);
	printf("最大公约数为:%d",max);
	min = find_min(a,b);
	printf("最小公倍数为:%d",min);
	return 0 ;
} 

Double click to view unformatted code.


Back to problem 59