#include <iostream>
#include <string>
using namespace std;
bool isPrime(int n);
int main()
{
int numbers[5];
for(int i=0;i<5;i++){
cout<<"Enter number "<<(i+1)<<": ";
cin>>numbers[i];
if(isPrime(numbers[i])){
numbers[2]=numbers[i];
}
}
if(isPrime(numbers[2])){
cout<<"The prime number is: "<<numbers[2]<<"\n";
}
cin>>numbers[0];
return 0;
}
bool isPrime(int n){
if (n == 0 || n == 1) {
return false;
}else {
for (int i = 2; i <= n / 2; ++i) {
if (n % i == 0) {
return false;
}
}
}
return true;
}
Comments
Leave a comment