I have code here for the program to list all prime numbers from 3-100. My main problem is that the program only prints out three. I think for some reason it's leaving the loop or something. I put a break within the for statement for it to leave the inner for loop immediately once it finds that the number is not prime so that it can print it out. But, it doesn't seem to be working.
#include <iostream> #include <conio.h> #include <cmath> using namespace std; int main() { bool prime = true; for (int x = 3; x <= 100; x++) { for (int y = 2; y <= (x - 1); y++) { if ((x % y) == 0) prime = false; break; } if (prime == true) cout<<x<<endl; } getche(); return 0; }
printf("2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97\n");(JK)