Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int n,x,i,d;
- int ct;
- double s=0;
- bool ok;
- cin>>n; ///nr de elemente
- ct=0;
- for(int i=1;i<=n;i++)
- {
- cin>>x;///valoarea citita
- ok=1; /// am presuspus ca x este prim
- if(x<2) ok=0;
- else
- {
- for(d=2;d*d<=x && ok==1;d++)
- if(x%d==0)ok=0;
- }
- if(ok==1)
- {
- ct++;
- s+=x;
- }
- }
- cout<<fixed<<setprecision(3)<<s/ct;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement