Advertisement
icatalin

Problema 8 tema, gresita, nu merge

Nov 27th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. //E gresita, nu merge.
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int x,n,cx,numar,S=0,OK=1,i;
  10.     cout<<"n="<<endl;
  11.     cin>>n;
  12.     for (x=n;x>1;x=x-1)
  13.     {
  14.         cx=x;
  15.         numar=x;
  16.         while(cx)
  17.         {
  18.         S=S + (cx%10);
  19.         cx=cx/10;
  20.         }
  21.  
  22.         for (i=2;i<=S-1;i++)
  23.         {
  24.             if (S%i==0)
  25.             OK=0;
  26.         }
  27.         if (OK==1)
  28.         cout<<numar<<endl;
  29.     }
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement