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