Advertisement
nicuvlad76

Untitled

Nov 19th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4. int main()
  5. {
  6. int n,x,i,d;
  7. int ct;
  8. double s=0;
  9. bool ok;
  10. cin>>n; ///nr de elemente
  11. ct=0;
  12. for(int i=1;i<=n;i++)
  13. {
  14. cin>>x;///valoarea citita
  15. ok=1; /// am presuspus ca x este prim
  16. if(x<2) ok=0;
  17. else
  18. {
  19. for(d=2;d*d<=x && ok==1;d++)
  20. if(x%d==0)ok=0;
  21. }
  22. if(ok==1)
  23. {
  24. ct++;
  25. s+=x;
  26.  
  27. }
  28. }
  29. cout<<fixed<<setprecision(3)<<s/ct;
  30. return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement