Skip to content

Required assistance #1390

Closed Answered by Shriharsh-Deshmukh
SD-4am-ind asked this question in General
Discussion options

You must be logged in to vote

Hi @SD-4am-ind,
To find out whether the given number is Prime or Not you can use for(int i=2;i<=n;i++).
But, it takes more time as it iterate till n th iteration. To minimize the iteration count we use i/2 instead of n as it reduces the iteration count to half. also to reduce beyond that you can use for(int i=2; i*i<=n;i++).

Happy coding 👍🏻

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SD-4am-ind
Comment options

Answer selected by SD-4am-ind
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants