I wrote a C++ program that prints all prime numbers lower than n, but the program keeps crashing while executing.
#include <iostream> using namespace std; bool premier(int x) { int i = 2; while (i < x) { if (x % i == 0) return false; i++; } return true; } int main() { int n; int i = 0; cout << "entrer un entier n : "; cin >> n; while (i < n) { if (n % i == 0 && premier(i)) cout << i; i++; } ; }
n % iwithi == 0i=1insteadn % iwithi = 2