Board logo

標題: [作業] 因數分解 (二) - 共有幾個因數 [打印本頁]

作者: 方浩葦    時間: 2024-4-19 11:33     標題: [作業] 因數分解 (二) - 共有幾個因數



本帖隱藏的內容需要回復才可以瀏覽

作者: 鄭豊翰    時間: 2024-5-11 15:44

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





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2