Sunday, 1 November 2015

C++ Program To Check Primness of 1D Array

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:-


C++ Program To Check Primeness Of An 1-D Array


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



Ghanendra Yadav
Ghanendra Yadav

I Am Ghanendra Yadav Owner Of This Website. I Love Programming, Web Developing, Logo Making, Banner And Website designing. Currently I Am Studying In NIT Warangal And Also Working With WSDC( As Web Application Developer ) In NIT Warangal For Any Query Mail Me I Will Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment