Advertisement
STANAANDREY

pb15XI2018

Nov 15th, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;// ||
  4.  
  5. int main() {
  6.  
  7. unsigned long n,nr,i=1,d,eprim,S,aparitii;
  8. S=0;
  9. i=1;
  10. aparitii=0;
  11. cout<<"n=";cin>>n;
  12.  
  13. while (i<=n)
  14. {
  15.     d=2;
  16.     eprim=1;
  17.     cout<<"nr"<<i<<'=';cin>>nr;
  18.     while (d<=nr/2&&eprim==1)
  19.     {
  20.         if (nr%d==0)
  21.         eprim=0;
  22.             d++;
  23.  
  24.     }
  25.     if (eprim) {
  26.  
  27.          aparitii++;
  28.         S+=nr;
  29. }
  30. i++;
  31. }
  32. long med=S/aparitii;
  33.    cout<<"media nr prime e: "<<med;
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement