- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int y;
- int start , end;
- cout << "請輸入起始數字:";
- cin >> start;
- cout << "請輸入結束數字:";
- cin >> end;
- for (int x = start; x <= end; x++)
- {
- bool isPrime = true;
- for (int i = 2; i < x; i ++)
- {
- if (x % i == 0)
- {
- isPrime = false;
- break;
- }
- }
- if (isPrime == true)
- {
- cout << x << "\t";
- }
- }
- system ("pause");
- return 0;
- }
複製代碼 |