ProAnswers.org

Write a C program to accept a number and check whether the number is prime or not

Write a program to accept a number and check whether the number is prime or not

#include /header file/
main() /main function/
{
int num,count,flag;
printf("
enter the number");
scanf("%d",&num);
if(num<=1)
{
printf("%d is not a prime number
“, num);
}
else
{
flag=0;
for(count=2;count<=num/2;count++)
{
if((num%count)==0) /if statement/
{
flag=1;
break;
}
}
}
if(flag==0)
{
printf(”%d is a prime number
“,num);
}
else
{
printf(”%d is not a prime number
",num);
}
}