返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y,sum=0;
  7.     cout<<"請輸入一數"<<endl;
  8.     cin>>x;
  9.     cout<<x<<"的因數:";
  10.     for(int i=1;i<=x;i++)
  11.         {
  12.         if(x%i==0)
  13.                 {
  14.             cout<<i<<" ";
  15.             y++;
  16.             sum=sum+i;
  17.         }
  18.     }
  19.     cout<<endl<<"共有"<<y<<"個"<<endl;
  20.     cout<<"他們的總和="<<sum<<"!"<<endl;
  21. system("pause");
  22. return 0;
  23. }
複製代碼

TOP

返回列表