程序代码:
#include<iostream> using namespace std; int count=0; int fun(int n); int main() { int a=30,b=20,c=15; cout<<fun(a)<<endl; cout<<fun(b)<<endl; cout<<fun(c)<<endl; return 0; } int fun(int n) { static int div; int i; if(count==0) { div=n; count++; return div; } else if(count!=0) { for(i=div;i>0;i--) { if(div%i==0&&n%i==0) { count++; div=i; return div; } } } }
C++菜鸟