# Thread: Prime numbers

1. ## Prime numbers

Code:
```#include<stdio.h>

int main()
{
int count = 0;
int num_limit = 100;

int factor = 1;
int result = 0;
for(num_limit = 100; count <= num_limit; count++)
{
if(count == 2)
{
printf("%d\n", count);
}

if(count == 3)
{
printf("%d\n", count);
}

if(count % 2 != 0 && count % 3 != 0)
{
while(factor <= count) // Trying to exclude perfect squares by finding the factors of number(count)
{
if(factor % count == 0) // Findin factors of number(count)
{
int fact_res = factor * factor; // fact_res the result of multiplying a factor by itself
if(fact_res == count)
{
result++; // if fact_res is equal to number(count) then number is a perfect square
}            // then result is increased by 1
}

factor++;
}

if(result == 0)
{
printf("%d\n", count); // if result is greater than 0 then number is not a prime number
}
}
}

return 0;
}```
It only outputs 2 and 3 then ends. Please help me out.

2. Step through your program with the debugger, and see what happens when the number being tested is 5 - that will show you.

I don't clearly understand what you were trying to do here. Looks like the mod test, but then -- well, it needs some print statements added to it with getchar()'s immediately afterward, to show you what's gone off the rails.

Please DO NOT start another thread on this!

Popular pages Recent additions