Write a program in C to check whether a number is a prime number using the function.

int PrimeOrNot(int);
int main()
int n1,prime;
printf(“\n\n Function : check whether a number is prime number or not :\n”);

printf(” Input a positive number : “);
prime = PrimeOrNot(n1);
printf(” The number %d is a prime number.\n”,n1);
printf(” The number %d is not a prime number.\n”,n1);
return 0;
int PrimeOrNot(int n1)
int i=2;
while(i<=n1/2) { if(n1%i==0) return 0; else i++; } return 1; }

Leave a Reply

Your email address will not be published. Required fields are marked *