I’ve been pulling my hair on the PRIME1 problem for some time. I seemingly take the correct input and output the correct answers when I do my own testing.
Would really appreciate a second pair of eyes here.
Hey there.
I think its printing format and return EXIT_SUCCESS all are fine…instead
Your code isn’t working on bigger i/p’s
Try
1
100000000 100000100
it should print
100000007
100000037
100000039
100000049
100000073
100000081
So now I think you can figure out the rest…
Also nxt tym if you have any trouble plz. explain your approach in brief…it helps others to find the bug fast.
Hi ! ,
Your approach doesn’t seem to give correct results for high values of the input. Why don’t you try the Sieve of Eratosthenes and modify it to suit the requirements of the question. I guess it’s a better approach which will fetch you correct results always as you can’t remember all those prime nos. you have in your code.
Adding static to a global variable does not make any difference. All global variables in C are static by default (and hence, will be auto-initialized to zero).
Also, all local variables of any function in c are having the storage auto as default. (These are not initialized to a particular value, and hence contain garbage).