Advertisement
STANAANDREY

T_20/3/2019

Mar 20th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main ()
  6. {
  7.   int v[1000],n,i,eprim,d,k;
  8.  
  9.   cout<<"n=";cin>>n;
  10.   for (i=0;i<n;i++)
  11.   {
  12.       cout<<"v["<<i<<"]=";
  13.       cin>>v[i];
  14.   }
  15.   cout<<"vector initial:"<<endl;
  16.   for (i=0;i<n;i++)
  17.   cout<<v[i]<<' ';
  18.  cout<<endl;
  19.   for (i=0;i<n;i++)
  20. {
  21.     eprim=1;
  22.     for (d=2;d<=sqrt(v[i]);d++)
  23.     if (v[i]%d==0)
  24.     eprim=0;
  25.  
  26.     if (eprim) {
  27.     for (k=i;k<n-1;k++)
  28.     v[k]=v[k+1];
  29.     n--;--i;
  30.     }
  31. }
  32. cout<<"vectorul final: "<<endl;
  33.  for (i=0;i<n;i++)
  34.   cout<<v[i]<<' ';
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement