初学c++,钱能50页,用筛法判断素数,我建了个a.txt.为什么没输出呀?我用的是 Vc 2008 Express Edition 5
#include<iostream>#include<vector>#include<fstream>usingnamespacestd;intmain(){vector...
#include<iostream>
#include<vector>
#include<fstream>
using namespace std;
int main(){
vector<int> prime(10000,1);
for(int i=2; i<100; ++i)
if(prime[i])
for(int j=i; i*j<10000; j++)
prime[i*j]=0;
ifstream in("a.txt");
for(int a;in>>a && a>1 && a<10000; )
cout<<a<<" is "<<(prime[a] ? "" :"not ")<<" a prime.\n";
} 展开
#include<vector>
#include<fstream>
using namespace std;
int main(){
vector<int> prime(10000,1);
for(int i=2; i<100; ++i)
if(prime[i])
for(int j=i; i*j<10000; j++)
prime[i*j]=0;
ifstream in("a.txt");
for(int a;in>>a && a>1 && a<10000; )
cout<<a<<" is "<<(prime[a] ? "" :"not ")<<" a prime.\n";
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询