Code producing wrong answer!

please see my code_https://ide.codingblocks.com/s/287506

here’s the corrected code

sir ,i initialise all even no as non prime no and try to find out prime no in odd no ,as all prime no are odd no

image

initiliase all values of the array to 0
and line 10 arr[i]= 1

when i used fuction it work fine https://ide.codingblocks.com/s/282332

and when i not use function it produce wrong answer https://ide.codingblocks.com/s/287506

sir,please reply i will be very thankful to you

can u share the q link where u are trying to submit and getting q answer
along the link share q name

@Nikhil-Jettley-2567269533523013 it might be so that u are overlooking the constraints

As I pointed out in the corrected code as well, your sieve function is not correct. First of all, while initializing the array, you were just initializing only odd numbers as prime. So , what your code was missing is checking if the number is divisible by 2 or not. That’s why some numbers like 6, 4 were getting printed