C Program to check whether the entered number is prime or not
/* C program to check whether the entered number is
prime or not. */
#include"stdio.h"
void
main()
{
int num, i, occur = 0;
printf("Enter a positive integer: ");
scanf("%d",&num);
for(i=2; i<=num/2; ++i)
{
if(num%i==0)
{
occur=1;
break;
}
}
if (occur==0)
printf("%d is a prime number.",num);
else
printf("%d is not a prime number.",num);
}
Output:
Comments
Post a Comment