關於輸入兩個值後輸出最大公約數和最小公倍數

//
//  main.cpp
//  practise
//
//  Created by 王爲衆 on 16/4/22.
//  Copyright © 2016年 王爲衆. All rights reserved.
//

#include <iostream>
#include<cmath>
int main()
{
    using namespace std;
  
    int x,y;
    cin>>x>>y;
    int max(int,int);
    cout<<"the max of two number is:"<<max(x,y)<<endl;
    int min(int, int);
    cout<<"the min of two number is:"<<min(x,y)<<endl;
    return 0;
    
    
    
}

int max(int a,int b)
{
    if(b!=0)
        return max(b,a%b);
    else
        return a;
        
}
int min(int a,int b)
{
    int c;
    c=a*b/max(a,b);
    return c;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章