C program for prime or not
#include<stdio.h>
int main()
{
int num,flag=0;
printf("Enter a number\t");
scanf("%d",&num);
//if the number is divisible by half of its number that is if n=6 then it is divided by 3 like n/3 and n is divided by 1,2,3 and if remainder is zero number is not prime
for(int i=2;i<=num/2;i++)
{
if(num%i==0)
{
flag=1;
break;
}
}
if (flag==1)
printf("Not Prime\n");
else
printf("\n Prime\n");
}
int main()
{
int num,flag=0;
printf("Enter a number\t");
scanf("%d",&num);
//if the number is divisible by half of its number that is if n=6 then it is divided by 3 like n/3 and n is divided by 1,2,3 and if remainder is zero number is not prime
for(int i=2;i<=num/2;i++)
{
if(num%i==0)
{
flag=1;
break;
}
}
if (flag==1)
printf("Not Prime\n");
else
printf("\n Prime\n");
}
out:
Enter a number 4
Not Prime
Comments
Post a Comment