Board logo

標題: 因數分解 (一) [打印本頁]

作者: 鄭又綸    時間: 2025-4-21 10:30     標題: 因數分解 (一)

設計一小程式, 使能快速列出任一正整數的所有因數, 參考執行畫面如下:

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x;
  7.     cout<<"請輸入一正整數: ";
  8.     cin>>x;
  9.     cout<<x<<"的因數有: ";
  10.     for(int i=1; i<=x; i++)
  11.     {
  12.          if(x%i==0)
  13.              cout<<i<<" ";
  14.     }
  15.     cout<<endl;
  16.     system("pause");
  17.     return 0;   
  18. }
複製代碼
備註
本單元解題需先了解何謂因數,以下網站可做參考https://www.junyiacademy.org/cou ... ade-5-a/g05-menzs5b
作者: 王繼樟    時間: 2025-4-22 19:58

此帖僅作者可見
作者: 李岱哲    時間: 2025-4-24 20:05

此帖僅作者可見
作者: 陳宥廷    時間: 2025-4-24 20:06

此帖僅作者可見




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