@ alixnua: 老兄:我根据您的程序写了一个,请指正: #include <iostream> using namespace std;
int prime(int start, int end) { int count = 0; for(int i = start; i <= end; i++) { int flag = 0; for(int j = 1; j <= i; j++) { flag += (i % j == 0); } if (flag == 2) { cout << i << endl; count++; } } return count; } int main() { int a, b; cout << "enter two numbers:"; cin >> a >>b; //cout << prime(a, b) << endl; cout<<"there are "<<prime(a, b) << " primes from " <<a<<" to "<<b<<endl; system("pause"); return 0; }