C program for verifying a number is prime or not.



#include <stdio.h>
int main()
{
    int n, i, is_prime;

    printf("Enter a positive integer: ");
    scanf("%d",&n);
is_prime=1;
    for(i=2; i<=n/2; i++)
    {
        // condition for nonprime number
        if(n%i==0)
        {
            is_prime=0;
        }
       
    }

    if (is_prime==1)
        printf("%d is a prime number.",n);
    else
        printf("%d is not a prime number.",n);
   
    return 0;
}

Comments

Popular posts from this blog

C program to verify a number is positive or not using else if.

C program for making pyramid containing N rows

C program for finding factors