C program to find prime numbers in entered array

      Comments Off on C program to find prime numbers in entered array

Find Prime numbers in entered array

C program to find prime numbers in entered array.Prime numbers are those which are divisible only by itself and 1.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int j,i,x[100],y,count;
clrscr();
printf("Enter size of array:- \n");
scanf("%d",&y);
printf("Enter elements in array:- \n");
for(i=1;i<=y;i++)
{
 scanf("%d",&x[i]);
}
printf("Prime numbers are:- \n");
  for(i=1;i<=y;i++)
{       count=0;
      for(j=2;j<=x[i]/2;j++)
      {
	   if(x[i]%j==0)
	   {
	   count++;
	   break;
	   }
      }

      if(count==0)
      {

       printf("%d\n",x[i]);
      }


}
getch();
}

OUTPUT

find prime numbers


Comment below if you are facing any problem.For updates subscribe to our newsletter if you love reading our post.


Also read

C Program to find Greatest Element in entered array
C Program Passing Array Elements to a function
C Program to Sort an array in Ascending Order
C program to enter a element into sorted array


Summary