I made a prime number finder, it finds the nearest prime that is above and below any integer (Does not work that well with giant numbers.)
Made this in cpp.sh
Why would I need the x=y+1-1;?
x=y; just doesnt seem to work
Why is this?
And I know my coding is far from clean or correct.
#include <iostream>
#include <string>
using namespace std;
int main(){
cout << "Prime nubers: " << endl;
int x=0, y=0, z=0, w=0;
cin >> x;
y = x-1+1; // for some reason this doesnt work without the +1-1
while (z!=1){
if (((x/2*2 != x) && (x/3*3 != x) && (x/5*5 != x) && (x/7*7 != x) && (x/13*13 != x)) || ((x == 7) || (x == 13) || (x == 3))){
cout << x << " is the nearest prime number!" << endl;
z=1;
}
x++;
}
while (w!=1){
if (((y/2*2 != y) && (y/3*3 != y) && (y/5*5 != y) && (y/7*7 != y) && (y/13*13 != y)) || ((y == 7) || (y == 13) || (y == 3))){
cout << y << " is the nearest prime number!" << endl;
w=1;
}
y--;
}
cout << " " << endl;
cout << " " << endl;
cout << " end of program" << endl;
return 0;
}