C program to find given number is prime or not

C program to find given number is prime or not


Prime Number Program in C, C assignment to find Prime Number


#include 
#include 
int main()
{
int num,i,count=0; 
printf("Enter a number: "); 
scanf("%d",&num); 
for(i=2;i<=num/2;i++)
{ 
if(num%i==0)
{ 
count++; 
break; 
} 
} 
if(count==0 && num!= 1)
{
printf("%d is a prime number",num); 
}
else
{
printf("%d is not a prime number",num); 
}
getch();
return 0; 
}



No comments:

Post a Comment