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