-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2_primelist.cpp
More file actions
43 lines (39 loc) · 808 Bytes
/
2_primelist.cpp
File metadata and controls
43 lines (39 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream>
#include<fstream>
using namespace std;
int primes[3500],l=0;
int main()
{
int i,k=2,temp;
bool a[32000];
for(i=0;i<32000;i++)
a[i]=true;
while(k*k<32000)
{
temp=1;
while(temp*k<32000)
{
a[temp*k]=false;
temp++;
}
primes[l++]=k;
while(a[k]==false)
{
k++;
}
}
primes[l++]=k;
while(k<32000)
{
if(a[k]==true)
primes[l++]=k;
k++;
}
ofstream MyFile;
MyFile.open ("2_primedump.csv", ios::out | ios::ate | ios::app | ios::binary) ;
for(i=0;i<l;i++)
{ cout<<primes[i]<<"\n";
MyFile<<primes[i]<<',';
}//cout<<"\n"<<float(end-start)<<"\n\n\n
return 0;
}