# Find all prime numbers from array

This article illustrates how to find all prime numbers from array in c/c++. Here is the source code and output of both the programs.

## C Programming language

#### Program

``````
#include<stdio.h>
#include<conio.h>
void main()
{
int arr,size,i,j,n;
clrscr();
printf("Enter number of elements you want to enter in array:- ");
scanf("%d",&size);
printf("Enter elements in array:- ");
for(i=0;i<size;i++)
{
scanf("%d",&arr[i]);
}
printf("Prime numbers are :- \n");
for(i=0;i<size;i++)
{
n=0;
for(j=2;j<arr[i];j++)
{
if(arr[i]%j==0)
{
n++;
break;
}
}
if(n==0)
{
printf("%d \n",arr[i]);
}
}
getch();
}
``````

#### After compiling and executing the above C program output is:- ## C++ Programming language

#### Program

``````
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr,size,i,j,n;
cout<<"Enter number of elements you want to enter in array:- ";
cin>>size;
cout<<"Enter elements in array:- ";
for(i=0;i<size;i++)
{
cin>>arr[i];
}
cout<<"Prime numbers are :- "<<endl;
for(i=0;i<size;i++)
{
n=0;
for(j=2;j<arr[i];j++)
{
if(arr[i]%j==0)
{
n++;
break;
}
}
if(n==0)
{
cout<<arr[i]<<endl;
}
}
getch();
}
``````

#### After compiling and executing the above C++ program output is:- Click here

#### About article

Written By:- Admin

Published on:- 27/10/2017

Published By:- Snapcout

Don't forget to share the article if you like it:-