返回列表 發帖

因數分解 (一)

本帖最後由 tonyh 於 2014-12-6 11:54 編輯
  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. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

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

TOP

  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.       
  13.        if(x%i==0)         
  14.            cout<<i<<" ";
  15.    }
  16.    cout<<endl;
  17.    system("pause");
  18.    return 0;
  19. }
複製代碼

TOP

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

TOP

  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.     system("pause");
  16.     return 0;
  17. }
複製代碼
http://fs-old.mis.kuas.edu.tw/~s1102137106/music/

TOP

  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<<"的因數有"<<endl;
  10. for(int a=1;a<=x;a++)
  11. {
  12.    if(x%a==0)
  13.     {
  14.       cout<<a<<" ";
  15.     }
  16.             
  17. }
  18.    
  19.   system("pause");
  20.   return 0;
  21. }
複製代碼

TOP

  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.     system("pause");
  16.     return 0;
  17. }
複製代碼

TOP

返回列表