Check Prime Number (C Program)
C Program to check if a number is Prime or not :
#include<stdio.h>
#include<stdbool.h>
int main()
{
int n;
bool prime;
printf("Enter the number\n");
scanf("%d", &n);
if(n==0 | n==1)
{
printf("%d is not a Prime Number\n", n);
return 0;
}
else
{
int i=2;
while (i<n)
{
if(n%i == 0)
{
printf("%d is not a Prime Number\n", n);
return 0;
}
i++;
}
printf("%d is a Prime Number\n", n);
}
return 0;
}
Comments
Post a Comment