Problem:- Program To Check Elements of a 1-D Integer An Array For Primness. Means in array your task is to find the prime number in an array or C++ Program To Check Primness of an Array.
Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.
Logic:- To Check primness of array we need to know that how to find the prime number then use a loop and run the program that's it we solve the problem. So Prime number is a number which only can be divided by the 1 or number itself, here are some prime number 2, 3, 5, 7, 11, 13, 17, 19. Important notice here 1 is not a prime number. Check Here C++ Program To Find Number Is Prime Or Not.
Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post
Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.
Solution:-
#include<iostream>
using namespace std;
int main()
{
int a[100],i,n,k,j,flag;
cout<<"Enter The Size of Array\n";
cin>>n;
cout<<"Enter The Element\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\n\n";
for(i=0;i<n;i++)
{
flag=0;
k=a[i]/2;
for(j=2;j<=k;j++)
{
if(a[i]%j==0)
{
flag=1;
break;
}
}
if(flag==1)
cout<<a[i]<<" is Not Prime\n";
else
cout<<a[i]<<" is Prime\n";
}
return 0;
}
Output:-
You May Also See
1. C++ Program To Find Number Is Even / Odd Using Pointer
2. C++ Program To Read Infinite Number Then Arrange Ascending Order Using Pointer
3. C++ Program To Average Of Array In Function Of Using Pointer
4 C++ Program For Swapping Two Number In Function Using Pointer
5. C++ Program For Store Employee Information And Display Using Structure
6. C++ Program For Adding Two Distance Using Structure
7. C++ Program For Employee Information Using Nested Structure
8. C++ Program For Book Details Using Structure
9. C++ Program To Read A Line By Line And Write Line By Line Using File
10. C++ Program For Reading A No. From File And Sum Of No. Line By Line Using File
Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.
Logic:- To Check primness of array we need to know that how to find the prime number then use a loop and run the program that's it we solve the problem. So Prime number is a number which only can be divided by the 1 or number itself, here are some prime number 2, 3, 5, 7, 11, 13, 17, 19. Important notice here 1 is not a prime number. Check Here C++ Program To Find Number Is Prime Or Not.
Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post
Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.
Solution:-
#include<iostream>
using namespace std;
int main()
{
int a[100],i,n,k,j,flag;
cout<<"Enter The Size of Array\n";
cin>>n;
cout<<"Enter The Element\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\n\n";
for(i=0;i<n;i++)
{
flag=0;
k=a[i]/2;
for(j=2;j<=k;j++)
{
if(a[i]%j==0)
{
flag=1;
break;
}
}
if(flag==1)
cout<<a[i]<<" is Not Prime\n";
else
cout<<a[i]<<" is Prime\n";
}
return 0;
}
Output:-
You May Also See
1. C++ Program To Find Number Is Even / Odd Using Pointer
2. C++ Program To Read Infinite Number Then Arrange Ascending Order Using Pointer
3. C++ Program To Average Of Array In Function Of Using Pointer
4 C++ Program For Swapping Two Number In Function Using Pointer
5. C++ Program For Store Employee Information And Display Using Structure
6. C++ Program For Adding Two Distance Using Structure
7. C++ Program For Employee Information Using Nested Structure
8. C++ Program For Book Details Using Structure
9. C++ Program To Read A Line By Line And Write Line By Line Using File
10. C++ Program For Reading A No. From File And Sum Of No. Line By Line Using File
0 Comments: