- #include<iostream>
- using namespace std;
- int main()
- {
- int x,y,GCF,smallest;
- int total=0;
- int count=0;
- cout<<"Enter a random whole number: ";
- cin>>x;
- cout<<"Enter another random whole number: ";
- cin>>y;
- cout<<x<<"&"<<y<<"的Greatest Common Factor:";
- smallest=x>y?x:y;
- for(int i=1;i<=x;i++)
- {
- if(x%i==0 && y%i==0)
- {
- GCF=i;
- }
- }
- cout<<GCF<<endl;
- system("pause");
- return 0;
- }
複製代碼 |