DMG

Dobar broj (maksimalan do n)

DMG
Jul 2nd, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool dobarbroj (int n)
  5. {
  6.      int a, s=0; bool p;
  7.      
  8.      a = n;
  9.      p = true;
  10.      while (a>10)
  11.      {
  12.          s = s + a%10;
  13.          if (a/10%10 <= s)
  14.          p = false;
  15.          a = a / 10;
  16.      }
  17.      return p;
  18. }
  19.  
  20. main()
  21. {
  22.       int n, max = 0;
  23.      
  24.       while (n!=0)
  25.       {
  26.             cin >> n;
  27.             if ((dobarbroj(n)==true)&&(n>max))
  28.             max = n;
  29.       }
  30.      
  31.       if (max == 0)
  32.       cout << "Ne postoji takav broj! " << endl;
  33.       else
  34.       cout << max << endl;
  35.      
  36.       system ("PAUSE");
  37. }
Advertisement
Add Comment
Please, Sign In to add comment