What's wrong in the following program-

#include<stdio.h>
main()
{
    int n,d=2,r;
    printf("Enter a number to check its divisibility:");
    scanf("%d",&n);
    for(d<n/2; d++;)
    {
        if(n%d!=0)
        {
            r=1;
            continue;
        }
        else
        {
            printf("%d is not a prime number.",n);
            break;
        }
    }
    if(r==1)
    {
        printf("%d is a prime number.",n);
    }
}

I want it to start the loop again after it finds "n%d!=0" true to check rest of the numbers,
(rather than using "n%d==0" and then simply breaking the loop).
But it is giving the following output for prime numbers:

"%d" is not a prime number."%d" is a prime number.

While the output for non-prime numbers is fine-

"%d" is not a prime number.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.