Check whether a number is a Prime number or not with C.
#include <stdio.h>
int main()
{
int i, num, isPrime=0;
printf("Enter any number to check prime: ");
scanf("%d", &num);
for (i = 2; i <= num / 2; i++)
{
if (num % i == 0)
{
isPrime = 1;
break;
}
}
if (isPrime == 0 && num > 1)
{
printf("%d is prime number", num);
}
else
{
printf("%d is composite number", num);
}
return 0;
}
Output:-
Enter any number to check prime : 89
89 is prime number
0 Comments