Advertisement
icatalin

Problema 5 tema suplimentara

Nov 27th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. //Toate numerele din patru cifre ce contin cel putin 1 cifra de 0 si au suma cifrelor egala cu 17.
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n=9999,a,b,c,d,s,cn;
  10.     for (n;n>=1000;n=n-1)
  11.         {
  12.         cn=n;
  13.         d=cn%10;
  14.         cn=cn/10;
  15.         c=cn%10;
  16.         cn=cn/10;
  17.         b=cn%10;
  18.         cn=cn/10;
  19.         a=cn%10;
  20.         s=a+b+c+d;
  21.         if ((b==0 || c==0 || d==0) && s==17)
  22.             cout<<n<<endl;
  23.         }
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement