Sieve of Eratosthenes C++ code
For the first time, I have developed a C++ application that compiles and runs flawlessly. I’ve made the decision to learn C++, and in order to become comfortable with the language, I’ve developed my first C++ program, which I wrote all by myself after only a few hours of instruction. (Also, no “Hello, World.” program has been written by me.
Example:1
#include<iostream> using namespace std; void primeSieve(int n) { int prime[100]={0}; for(int i=2;i<=n;i++) { if(prime[i]==0){ for(int j=i*i;j<=n;j+=i){ prime[i]==1; } } } for(int i=2;i<=n;i++) { if(prime[i]==0) { cout<<i<<" ";
}cout<<endl;
}
} int main() { int a; cin>>a; primeSieve(a); }