{ A destination to learn coding }

Code to check for a prime number.


#include <stdio.h>
#include <math.h>
int main()
{
int a,i,b=1;
printf("Enter a number\n");
scanf("%d",&a);

if(a==1)
{
	printf("Not a prime number");
}

else if(a==2)
{
	printf("Prime number");
}

else if (a>2)
{

   	for(i=2;i<=sqrt(a);i++)
  	{
		if(a%i==0)
		{
		b+=1;
                break;
		}
	
  	}

   	if(b>1)
	{
	printf("Not a prime number");
	}
	else
	{
	printf("Prime Number");
	}

}

else
{
	printf("Invalid Input");
}
		
return 0;
}