Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, x, nrn=0;
  8. float s=0;
  9. cin >> n;
  10. for(int i=1; i<=n; ++i)
  11. {
  12. cin >> x;
  13. bool prim=true;
  14. if(x<2) prim=false;
  15. else
  16. if(x==2) prim=true;
  17. else
  18. if(x%2==0) prim=false;
  19. else
  20. for(int j=3; j*j<=x; j=j+2)
  21. if(x%i==0) prim=false;
  22. if(prim==true)
  23. {
  24. s=s+x;
  25. nrn++;
  26. }
  27. }
  28. float med=s/nrn;
  29. if(med==0) cout << "NU EXISTA";
  30. else
  31. cout << setprecision(3) << med;
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement