- #include<iostream>
- #include<string>
- #include<cstdlib>
- using namespace std;
- int gcd(int a,int b)
- {
- int bigger,samller;
- if(a > b)
- {
- bigger = a;
- samller = b;
- }
- else
- {
- bigger = b;
- samller = a;
- }
- int ret = bigger%samller;
- if(ret == 0)
- return samller;
- gcd(ret,samller);
- }
- int main(void)
- {
- int a,b;
- string tmp;
- cout<<"input two numbers" << endl;
- cin >>tmp;
- a = std::atoi(tmp.c_str());
- cin >>tmp;
- b = std::atoi(tmp.c_str());
- cout <<gcd(a,b)<<endl;
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2404201512435.html
来源: http://www.codesnippet.cn/detail/2404201512435.html