[Solved] what is wrong with this code? (to check whether a given number is a prime number) [closed]


your if statement is never true duo to n and x are not initialized. Therefore you only get your else as return. Moreover your expression n>1; and a != n && n < a; return a bool which is not compered to anything. In that case you need to use a for loop.

Here is a link About for loops

int main()
{
    int a,n,x = 0;

    printf("enter a number: ");
    scanf("%d",&a);
    for(n=2; n<=a/2; ++n)
    {
        if(a%n==0)
        {
            x=1;
            break;
        }
    }
    if (x==0)
        printf("",n);
    else
        printf("a is not a prime no");    
    return 0;
}

1

solved what is wrong with this code? (to check whether a given number is a prime number) [closed]