Advertisement
aimon1337

nr prime dintr-un vector

Jan 29th, 2020
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1.  #include<iostream>
  2. using namespace std;
  3.  int a[100],n,x;
  4.  
  5.  int prim(int n)
  6.  {
  7.  if(n<=1) return 0;
  8.  int i=2;
  9.  while(i<=n/2)
  10.     if(n%i==0)return 0;
  11.     else i++;
  12.  return 1;
  13.  }
  14.  int numara(int p,int u)
  15.  { int m,n1,n2;
  16.  if(u==p) if(prim(a[p])) return 1;
  17.     else return 0;
  18.     else
  19.     {
  20.     m=(p+u)/2;
  21.     n1=numara(p,m);
  22.     n2=numara(m+1,u);
  23.     return n1+n2;
  24.     }
  25.  }
  26.  int main()
  27.  {
  28.  cin>>n;
  29.  for(int i=1;i<=n;i++)
  30.     cin>>a[i];
  31.  cout<<"numarul de numere prime="<<numara(1,n);
  32.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement