-1

(https://i.stack.imgur.com/kjquh.png)

Trying to increment the integer variable by count each time the if condition returned true.

it is not working properly the count is showing zero at all times

i am trying to find the program for prime number using loop

  • 1
    Please post your code here as text, not a screenshot. Also, check out [this article]https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) for tips on debugging your code. – Code-Apprentice Jul 19 '23 at 14:35
  • Never post images of code. Post it as text. – Unmitigated Jul 19 '23 at 14:35
  • Welcome to Stack Overflow! Relevant code and error messages need to be included in your question *as text*, [not as pictures of text](https://meta.stackoverflow.com/q/285551/328193). Just linking to screen shots makes it more difficult for people to help you. To learn more about this community and how we can help you, please start with the [tour] and read [ask] and its linked resources. – David Jul 19 '23 at 14:36
  • [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551) – OH GOD SPIDERS Jul 19 '23 at 14:36
  • 1
    Additionally... This is a good opportunity for you to start familiarizing yourself with [using a debugger](https://stackoverflow.com/q/25385173/328193). When you step through the code in a debugger, which operation first produces an unexpected result? What were the values used in that operation? What was the result? What result was expected? Why? – David Jul 19 '23 at 14:36
  • `i%num == 0` for the numbers in the range of `[2, num]` will only ever be true once, when `i == num`. I'd also encourage using brackets/braces a little more liberally. – Rogue Jul 19 '23 at 14:37
  • Thank you so much for the enlightenment as a beginner I am yet to become familiar with the platform. – HRISHIKESH DEY Jul 19 '23 at 14:58

1 Answers1

0

Change the if condition or statement from if(i%num == 0) to if(num%i == 0). It will lead to correct output. In our case input is number 10 it is divisible by number 2 and number 5. Then the program will print 10 is not an prime number.

Abishek
  • 28
  • 1
  • 7