Can you tell me what's wrong with this code?

Write your question here.

thanks everyone my question has been answered :)
Last edited on
Here is a problem:

for (int a=2; a<=(num/2); a++)

when a = 2, a <= num/2 will not happen for num = 1, 2, 3.
Last edited on
Also, you have another problem. You're getting numbers that are not prime numbers. Prime numbers, by definition, are numbers that have two positive number divisors; one and itself.

for example, 15 is not a prime number by definition(it's a composite number). 15 could be divided like 15/1, 15/3, 15/5, 15/15. However, numbers like 13 and 2 are only divisible by themselves and by one. This is what you need to take into consideration.be

Here is a list of prime numbers up to 100

2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97.
Last edited on
Topic archived. No new replies allowed.