  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # I am making a prime number checker: when I try to run it, it stopped working  » c » I am making a prime number checker: when I try to run it, it stopped working

By : Abanoub Samir
Date : September 23 2020, 04:00 AM
I hope this helps you . ,
Try this Code. code :
``````#include <stdio.h>

int main()
{
int x,i,counter=0;
printf("Input number!\t");
scanf("%d",&x);

for(i=1;i<=x;i++)
{
if(x%i==0)
{
counter++;
}

}

if(counter<=2)
{
printf("%d is a prime number.",x);
}
else
{
printf("%d is not a prime number.",x);
}
return 0;
}
`````` ## Prime number checker returning every number as prime

By : J. Silva
Date : March 29 2020, 07:55 AM
wish helps you Because you are not returning after you find a number is not prime. So it checks all the way until i-1 and checks if i-1 Mod i = 0 which it never will be. So it says all numbers are prime.
Also, you only have to check if the prime numbers from 2 to sqrt(i) divide into i to see if i is a prime number or not. ## Prime number checker returns any number as a prime. C

By : user2170316
Date : March 29 2020, 07:55 AM
hope this fix your issue This program is supposed to print every number that is not prime from 3 to 100. But it acts like it doesn’t interpret well the last if statement. , You forgot to set flag to a non-zero value:
code :
``````for (i = 3; i < 100; i++){
flag = 1;
for(k = 2; k <= i/2; ++k){
if(i % k == 0) {
flag = 0;
break;
}
}
if (flag==0)  { printf("not prime : %d\n",i); }
}
`````` ## Python Prime number checker not working

By : Rogan Melo
Date : March 29 2020, 07:55 AM
this one helps. In Python 3.x, you need to convert your variable number to int like this:
code :
``````number = int(input("Please enter a number: "))
``````
``````>>> number = input("Please enter a number: ")
>>> type(number)
<class 'str'>
``````
``````>>> number = input("Please enter a number: ")
>>> type(number)
<type 'int'>
`````` ## Prime Number checker is not working

By : jackson bai
Date : March 29 2020, 07:55 AM
I hope this helps you . Remove equal to operator in n <= y. Start your loop from 2. It must be like this. ( long n =2; n < y; n++) ## my prime number checker function not working properly

By : user3368996
Date : March 29 2020, 07:55 AM
wish helps you So this function is just supposed to return 0 if not prime and 1 if prime. Am I seeing something wrong? for example, when I give it 39, it says it returns 1 although 39 is not a prime. , In this loop
code :
``````for(loop_counter ; loop_counter < number ; loop_counter++){
``````
``````int is_prime( unsigned int n )
{
int prime = n % 2 == 0 ? n == 2 : n != 1;

for ( unsigned int i = 3; prime && i <= n / i; i += 2 )
{
prime = n % i != 0;
}

return prime;
}
``````
``````int prime = n % 2 == 0 ? n == 2 : n != 1;
``````
``````    for ( unsigned int i = 3; prime && i <= n / i; i += 2 )
^^^^^^
``````
``````        prime = n % i != 0;
``````
``````for ( unsigned int i = 3; prime && i <= n / i; i += 2 )
^^^^^
``````
``````for ( unsigned int i = 3; prime != 0 && i <= n / i; i += 2 )
^^^^^^^^^^
`````` 