Program in C to print all prime number from array.
#include<iostream> using namespace std; int main() { const int size=35; int arr[size],n,i,p,j; cout<<"Enter the size of array:-"; cin>>n; if(n>size) { cout<<"Invalid array size!."; return 0; } cout<<"Enter "<<n<<" numbers:-"; for(i=0;i<n;i++) { cin>>arr[i]; } cout<<"Prime numbers "; for(i=0;i<n;i++) { for(p=1,j=2;j<=arr[i]/2;j++) { if(arr[i]%j==0) { p=0; break; } } if(p==1) cout<<" "<<arr[i]; } return 0; }
Output:-
0 Comments