adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C to print all prime number from array.

Program in C to print all prime number from array.


#include<iostream>
 using namespace std;
  int main()
   {
     const int size=35;
     int arr[size],n,i,p,j;
     cout<<"Enter the size of array:-";
     cin>>n;
     if(n>size)
      {
       cout<<"Invalid array size!.";
       return 0;
  }
  cout<<"Enter "<<n<<" numbers:-";
     for(i=0;i<n;i++)
      {
       cin>>arr[i];
  }
   cout<<"Prime numbers ";
   for(i=0;i<n;i++)
    {
     for(p=1,j=2;j<=arr[i]/2;j++)
      {
       if(arr[i]%j==0)
         {
          p=0;
          break;
    }
   }
   if(p==1)
    cout<<"  "<<arr[i];
    }
      return 0;
   }
Output:-





Post a Comment

0 Comments