回復 1# may - #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int x1,x2, sum1=0,sum2=0;
- cout<<"請輸入2個正整數: ";
- cin>>x1>>x2;
- cout<<x1<<"的因數有: ";
- for(int i=1; i<=x1; i++)
- {
- if(x1%i==0)
- {
- cout<<i<<" ";
- sum1++;
- }
- }
- cout<<endl<<x2<<"的因數有: ";
- for(int i=1; i<=x2; i++)
- {
- if(x2%i==0)
- {
- cout<<i<<" ";
- sum2++;
- }
- }
- cout<<endl<<x1<<"總共有"<<sum1<<"個因數!";
- cout<<endl<<x2<<"總共有"<<sum2<<"個因數!"<<endl;
- if(sum1>sum2)
- cout<<x1<<"的因數比"<<x2<<"多"<<sum1-sum2<<"個"<<endl<<endl;
- else if(sum2>sum1)
- cout<<x2<<"的因數比"<<x1<<"多"<<sum2-sum1<<"個"<<endl<<endl;
- else
- cout<<x1<<"的因數和"<<x2<<"的因數,一樣多。"<<endl<<endl;
- goto re;
- return 0;
- }
複製代碼 |