Code give primes till 200. Maybe, readable. Let community decide it.
I show another piece of mini-workflow. Can you read it easy.
Code:
#include<iostream>
#include<vector>
using namespace std;
int main(){
int n=3, m; vector<int>primes(0); bool op=1;
primes.push_back(2); primes.push_back(3);
while(n<200){ n++;
for(m=n-1; m>1; m--)if(n%m==0){op=0; break;}
switch(op){
case 0: op=1;break;
case 1: primes.push_back(n);break;
}
}
m=0;
do{ cout<<primes[m]<<endl; m++;}
while(m<primes.size());
cin.get();
}
Hey, Testers! It's another version of prime makers. More user-friend and...
Provide options. Just run it, and say your opinions.;)
Code:
#include<iostream>
#include<vector>
using namespace std;
int main(){
int n, m, a, b;
vector<int>primes(0); bool op=1;
cout<<"Give two positive integer for specifying the interval in which you wonder the prime numbers: ";
cin>>a>>b; cin.ignore(); cout<<endl;
if(a-b==0){cout<<"It is not an interval. "; cin.get(); return 0;}
if(a<0 || b<0){cout<<"Please give POSITIVE numbers. "; cin.get(); return 0;}
(a<b) ? n=a : n=b;
(n==b) ? b=a : b;
(n>=1) ? n-- : n;
while(n<b){ n++;
for(m=n-1; m>=1; m--)if(n%m==0 && m!=1){op=0; break;} ;
switch(op){
case 0: op=1;break;
case 1: primes.push_back(n);break;
}
}
m=0;
do{ cout<<primes[m]<<endl; m++;}while(m<primes.size());
if(m==1)cout<<"\n\nThere is "<<primes.size()<<" prime number between the two whole numbers." ;
if(m>=2)cout<<"\n\nThere are "<<primes.size()<<" prime numbers between the two whole numbers.";
cin.get();
}