Skip to main content
Program to find if the given no. is prime or not. The function should accept the number as argument and return if the no. is prime or not.
CODING:
#include <stdio.h>
int checkPrimeNumber(int n);

int main()

{
    int n, flag;

    printf("Enter a positive integer: ");

    scanf("%d",&n);


    flag = checkPrimeNumber(n);

    if(flag==1)

        printf("%d is not a prime number",n);
    else
        printf("%d is a prime number",n);

    return 0;

}


{

int i;

    for(i=2; i <= n/2; ++i)

    {
        if(n%i == 0)
            return 1;
    }

    return 0;

}

Comments

Post a Comment