Q:

C Program to check whether a number is a prime number or not using the function

0

C Program to check whether a number is a prime number or not using the function

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<stdio.h>
int PrimeOrNot(int);
int main()
{
    int n1,prime;
	printf("\n\n Function : check whether a number is prime number or not :\n");
	printf("---------------------------------------------------------------\n");    	

    printf(" Input a positive number : ");
    scanf("%d",&n1);
    prime = PrimeOrNot(n1);
   if(prime==1)
        printf(" The number %d is a prime number.\n",n1);
   else
      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;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now