求最大公约数

来源:互联网 发布:mac如何删除重复照片 编辑:程序博客网 时间:2024/06/03 14:47
#include <iostream>using namespace std;int gcd(int M, int N){int R;R=M % N;if(M<=0 || N<=0)return 0;if(R == 0)return N;return gcd(N,R);}int main(){int m,n,r;cout<<"Please input two numbers:";cin>>m>>n;r=gcd(m,n);cout<<r<<" is the greatest common divisor"<<endl;return 0;}

0 0
原创粉丝点击