返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){

  5. int i;
  6. int j=1;
  7. int k=0;
  8. int l=0;
  9. cout<<"請輸入一正整數: ";
  10. cin>>i;
  11. cout<<i<<"的因數有: ";

  12. while(j<=i){
  13.         if(i%j==0){
  14.         k=k+j;
  15.         l++;
  16.         cout<<j<<" ";
  17.         }

  18.         j++;

  19.             }
  20. cout<<endl;
  21. cout<<"共有"<<l<<"個因數"<<endl;
  22. cout<<"總和為"<<k<<endl;
  23. system("pause");
  24. return 0;


  25. }
複製代碼

TOP

返回列表