Numbers that has no factors other than 1 and itself are known as Prime Numbers.
for ex- 3 , 5 ,7 , 11 etc.. these all numbers are prime numbers.
Number is taken as input in this program then it is made divide by numbers that
are below it by using loop if more than two times it is divisible then it will give
you output that it is not prime otherwise it is prime.
break; is used to break the statement and come straight to the output if it is true
and not to check other statements.
Program
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i,m=1;
printf("Enter the number you want to check
= ");
scanf("%d",&n);
for(i=2 ; i < n ; i++)
{
if(n % i == 0)
{
printf("%d is not prime",n);
m=0;
break;
}
}
if (m == 1)
{
printf("%d is
prime",n);
}
}
Output:
Post a Comment