Hi, this is the updated code; it still gives me the same error. I tried to divide only by the prime numbers already found.
#include <iostream>
#include <new>
using namespace std;
#include <stdio.h>
#include <math.h>
class getprime
{ int * x, * y;
bool prime;
//int div;
public:
bool checkprime(int, int*);
int printprime(int ,int);
};
bool getprime::checkprime(int n, int* z)
{ int div = 2;
if(n==1) return false;
else if(n<=3) return true;
if(n%div==0) return false;
for(int i = 0; i <= sqrt(n); i++)
{
if(z[i] != 0)
{ if(n%(z[i]) == 0) return false;
}
}
return true;
}
int getprime::printprime(int x1, int x2)
{ prime = false;
x = new (nothrow) int;
x = &x1;
int maxnum = sqrt(x2);
y = new (nothrow) int[maxnum/2];
*y = 0;
int j = 0;
while(*x<=x2)
{
prime = this->checkprime(*x,y);
if(prime)
{
if(*x <= maxnum)
{ y[j] = *x;
j++;
}
printf("%d \n", *x);
}
(*x)++;
}
}
int main()
{ int i,tcases; // number of cases to analyze
int *cases, *x;
getprime primeobj;
scanf("%d", &tcases);
if(tcases >10) return 1;
cases = new (nothrow) int[2];
for(i=0;i<tcases;i++)
{ scanf("%d",&cases[0]);
scanf("%d", &cases[1]);
printf("%d %d \n",cases[0],cases[1]);
// while(cases[0]<=cases[1])
{ primeobj.printprime(cases[0],cases[1]);
// cases[0]++;
}
printf("\n");
}
delete x;
}