Dobrý den,
chtěl bych se zeptat kde bych mohl mit chybu? program je v pohode prelozitelny, ale pri spusteni havaruje v mainu pri vypisovani pole, nevim co s tim delat :-)
#include <iostream>
using namespace std;
void find_primes(int max_prime, int *field_of_primes, int &size_of_the_field);
int main()
{
int a, b = 0;
int *field = 0;
cin >> a;
find_primes(a, field, b);
a = 0;
while(a < b)
cout << field[a++] << endl;
delete []field;
system("pause");
}
void find_primes(int max_prime, int *field_of_primes, int &size_of_the_field)
{
int a = 2, b = 2, c = 0;
bool p = false;
size_of_the_field = 1;
while(a++ < max_prime)
{
p = true;
while(b < a)
if(a % b++ == 0)
p = false;
b = 2;
if(p)
size_of_the_field++;
}
field_of_primes = new int[size_of_the_field];
a = 2;
b = 2;
field_of_primes[0] = 2;
c = 1;
while(a++ < max_prime)
{
p = true;
while(b < a)
if(a % b++ == 0)
p = false;
b = 2;
if(p)
field_of_primes[c++] = a;
}
}
děkuji za odpověď