Posts

Showing posts with the label prime number

C Program to check prime number

Image
C Program to  check prime number  #include<conio.h> #include<stdio.h> void main() {     int p,i;     clrscr();     printf("enter no. to check prime: ");     scanf("%d",&p);     for(i=2;i<p;i++)     if(p%i==0)     {         printf("%d is not a prime number ",p);         break;     }     if(i==p)     printf("%d is prime number",p);     getch(); } Explanation int p,i;       p and i are two variables of integer type ; printf() and scanf() are predefine functions use for read and write respectively. for(i=2;i<p;i++) for loop use to check prime number  count  if(p%i== 0) if p % i = 0 then it means 'p' has any common factor between 1 to p which means it is not a prime...