nicuvlad76

Untitled

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