online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <iostream> #include <bits/stdc++.h> using namespace std; const int N = 100000; vector<int> primes; int p[N] = {0}; // wrong void sieve() { for (int i = 2; i <= N; i++) { if (p[i] == 0) { primes.push_back(i); for (int j = i; j <= N; j += i) { p[j] = 1;//not prime } } } } int main() { sieve(); // build this sieve once for all int t; cin >> t; while (t--) { int m, n; cin >> m, n; bool segment[n - m + 1]; // this line is causing segmentation fault . why? // cout << "error" << endl; for (int i = 0; i < n - m + 1; i++) { segment[i] = 0; } for (auto x : primes) { // stop the loop if the remaining numbers are not needed if (x * x > n) { break; } int start = (m / x) * x; if (x >= m && x <= n) { start = 2 * x; } // mark all the multiples of x in range from start to n as not primes for (int i = start; i <= n; i += x) { segment[i - m] = 1; } } // print primes from m...n for (int i = m; i <= n; i++) { if (segment[i - m] == 0 ) { cout << i << endl; } } cout << endl; } return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue