Pages

Tuesday, November 10, 2015

C Program for prime no.

/*A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. */

Program

#include<stdio.h>
void main()
{
int no,i;
printf("enter the number:");
scanf("%d",&no);
for(i=2;i<no;i++)
{
if(no%i==0)
break;
}
if(i==no)
printf("%d is a prime number.\n",no);
else
printf("%d is not a prime number.\n",no);

}

Output
enter the number:7
7 is a prime number.

No comments:

Post a Comment