Board logo

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

作者: tonyh    時間: 2013-6-8 14:34     標題: 因數分解

本帖最後由 tonyh 於 2013-6-8 14:42 編輯

讓使用者任意輸入一正整數, 電腦回應此正整數的因數有那些.
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     cout<<"請輸入一正整數: ";
  8.     cin>>a;
  9.     cout<<a<<"的因數有: ";
  10.     for(int i=1; i<=a; i++)
  11.     {
  12.         if(a%i==0)
  13.             cout<<i<<" ";
  14.     }
  15.     cout<<endl;
  16.     system("pause");
  17.     return 0;   
  18. }
複製代碼

作者: 黃柏維    時間: 2013-6-8 14:38

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. int a;
  7. cout<<"請輸入一正整數: ";
  8. cin>> a;
  9. cout<<a<<"的因數有: ";
  10. for(int i=1;i<=a;i++)
  11. {
  12.     if(a%i==0)     
  13.       cout<<i<<" ";   
  14. }
  15. cout<<endl;  
  16. system("pause");   
  17. return 0;   
  18. }
複製代碼

作者: 蘇昱安    時間: 2013-6-8 14:41

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     cout<<"請輸入一正整數: ";
  8.     cin>>a;
  9.     cout<<a<<"的因數有: ";
  10.     for(int i=1; i<=a; i++)
  11.     {
  12.         if(a%i==0)
  13.             cout<<i<<" ";
  14.     }
  15.     cout<<endl;
  16.     system("pause");
  17.     return 0;   
  18. }
複製代碼

作者: 劉泳鱔    時間: 2013-6-8 14:41

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

作者: 黃崇維    時間: 2013-6-8 14:42

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     cout<<"請輸入一正整數: ";
  8.     cin>>a;
  9.     cout<<a<<"的因數有: ";
  10.     for(int i=1;i<=a;i++)
  11.     {
  12.         if(a%i==0)
  13.         cout<<i<<" ";
  14.     }
  15.     cout<<endl;   
  16.     system("pause");
  17.     return 0;
  18. }
複製代碼

作者: 長逸    時間: 2013-6-8 14:43

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     cout<<"請輸入一正整數: ";
  8.     cin>>a;
  9.     cout<<a<<"的因數有: ";
  10.     for(int i=1; i<=a; i++)
  11.     {
  12.         if(a%i==0)
  13.             cout<<i<<" ";
  14.     }
  15.     cout<<endl;
  16.     system("pause");
  17.     return 0;   
  18. }
複製代碼

作者: 林以諾    時間: 2013-6-8 14:47

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     cout<<"請輸入一個正整數";
  8.     cin>>a;
  9.     cout<<a<<"的因數:";
  10.     for(int i=1;i<=a;i++)
  11.     {   
  12.     if(a%i==0)
  13.     cout<<i<<" ";
  14.             }
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

作者: 鎧言    時間: 2013-6-8 14:48

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     cout<<"請輸入一正整數:";
  8.     cin>>a;
  9.     cout<<a<<"的因數有:";
  10.     for(int i=1;i<=a;i++)
  11.     {
  12.         if(a%i==0)
  13.             cout<<i<<" ";
  14.     }   
  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

作者: 郭凡瑛    時間: 2013-6-8 14:54

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main ()
  5. {
  6. int a;
  7. cout<<"請輸入一正數:";
  8. cin>>a;
  9. cout<<a<<"的因數有:";
  10. for(int i=1; i<=a; i++)   
  11. {
  12.          if(a%i==0)
  13.          cout<<i<<"  ";
  14.          
  15. }
  16. cout<<endl;
  17. system("pause");
  18. return 0;      
  19.     }
複製代碼

作者: 張瀚仁    時間: 2013-6-13 21:02

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     cout<<"請輸入一正整數"<<endl;
  8.     cin>>a;
  9.     cout<<a<<"的因數有:";
  10.     for(int i=1;i<=a;i++)
  11.     {
  12.          if(a%i==0)
  13.          cout<<i<<" ";        
  14.     }
  15.     cout<<endl;
  16.     system("pause");   
  17.     return 0;
  18. }
複製代碼





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