乙_1013 数素数 (20分)
![](https://img2020.cnblogs.com/blog/1587586/202005/1587586-20200525143258446-527773937.png)
分析: (1) 程序一直有错,半天才发现是自己的命名有问题;谨慎命名;
(2) 切记退出循环
(3)学会调试
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
bool isPrime(int n){
if(n==2||n==3) return true;
for(int i=2;i<=sqrt(n);i++){
if(n%i==0) return false;
}
return true;
}
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
bool isPrime(int n){
if(n==2||n==3) return true;
for(int i=2;i<=sqrt(n);i++){
if(n%i==0) return false;
}
return true;
}
int main(){
int n, m;
cin >> m >> n;
vector<int> vc;
int count =0;
for(int i=2;;i++)
{
if(isPrime(i)) {
count ++;
if(count>=m && count <= n) vc.push_back(i);
if(count == n) break;
}
}
int j;
for (j=1; j<=vc.size();j++)
{
cout <<vc[j-1];
if(j<=vc.size()-1){
if(j%10==0) {
cout << endl ;
}
else cout << " ";
}
}
return 0;
}
cin >> m >> n;
vector<int> vc;
int count =0;
for(int i=2;;i++)
{
if(isPrime(i)) {
count ++;
if(count>=m && count <= n) vc.push_back(i);
if(count == n) break;
}
}
int j;
for (j=1; j<=vc.size();j++)
{
cout <<vc[j-1];
if(j<=vc.size()-1){
if(j%10==0) {
cout << endl ;
}
else cout << " ";
}
}
return 0;
}