question:https://hack.codingblocks.com/contests/c/509/157
answer:https://ide.codingblocks.com/#/s/23959
1/4 passed whats wrong in this code?
Print primes august
So, Two problems with this code.
- for loop of i should be till <=n and not <n, because n may also be a prime number.
- return 0. this will exit the main function. that means no primes will be printed when if(i%j==0) holds true. Actually what you want is come out of j loop and don’t print that i and move to next i.
Try solving the second bug.
Incase you cnt figure it out, check my submission.
https://ide.codingblocks.com/#/s/23971
NOTE: We can check whether a number is prime or not in O(root(N)) as well.