Your code probably does its job (haven't tried it) but I suggest some refactorings:
You can easily avoid the global variables primes and j by declaring them inside main. Yes, you will have to pass additional arguments to goldbach but that's fine.
It is hard to understand what the meaning of j is. You should use a more expressive name like last_prime_index.
In is_prime you declare another variable j which shadows the global j. This can easily cause errors.
In is_prime, instead of j < n/2, you should check if j <= sqrt(n). This will make your code much more performant for larger numbers.
In is_prime, instead of declaring a flag, you could simply return 0 or 1.
In goldbach, the flag variable is not used.
The goldbach function does two different things, calculation and output. It could be split into two separate functions.
You should check if j < 100000 before incrementing it.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Your code probably does its job (haven't tried it) but I suggest some refactorings:
You can easily avoid the global variables
primes
andj
by declaring them insidemain
. Yes, you will have to pass additional arguments togoldbach
but that's fine.It is hard to understand what the meaning of
j
is. You should use a more expressive name likelast_prime_index
.In
is_prime
you declare another variablej
which shadows the globalj
. This can easily cause errors.In
is_prime
, instead ofj < n/2
, you should check ifj <= sqrt(n)
. This will make your code much more performant for larger numbers.In
is_prime
, instead of declaring aflag
, you could simply return 0 or 1.In
goldbach
, theflag
variable is not used.The
goldbach
function does two different things, calculation and output. It could be split into two separate functions.You should check if
j < 100000
before incrementing it.