Monday 10 February 2020

CPP program to print the prime number elements in an array

Source Code:

#include<iostream>
using namespace std;
int main()
{
int a[10]={3,5,6,7,8},j,p;
int i;
cout<<"The prime numbers are: "<<endl;
for(i=0;i<5;i++)
{
j=2;
p=1;
while(j<a[i])
{
if(a[i]%j==0)
{
p=0;
break;
}
j++;
}
if(p==1)
{
cout<<a [i]<<" ";
}
}

return 0;
}

Program Output:

No comments:

Post a Comment