Program in C++ to find greatest prime number from array.
#include<iostream> using namespace std; int main() { const int size=35; int arr[size],n,i,p,j,l; 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]; } 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) { if(arr[i]>l) l=arr[i]; } } cout<<"Greatest Prime numbers "<<l; return 0; }
Output:-
0 Comments