Before know the source code we need to understand the concept about primat number .

what is prime number?

>>The number which is only divisible by 1 or itself.

or

>>The number which do not come in others numbers multiplication table .

To check the given number is prime ,firstly user must input the number .After getting number from the user ,we need to divide that number by each 1 to n (input number) by using for loop .then we need to count how many times input number is perfectly divided.

If count is equal to 2 ,that means the input number is divided by 1 or itself,that means input number is a prime number.

The source code is given below and output also:

main()
{
int a,i,d;
printf(“enter a number to check prime\n “);
scanf(“%d”,&a);
for(i=1;i<=a;i++)
{
if(a%i==0)
{
d++;
}
}
if(d==2)
{
printf(“prime number”);
}
else
{
printf(“not a prime number”);
}
}

output:

enter a number to check prime 7 prime number

Leave a Reply

Your email address will not be published. Required fields are marked *