Advertisement
JosepRivaille

P35537: Nombres Creixents

Apr 4th, 2015
1,227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. bool es_creixent(int n) {
  6.     if (n < 10) return true;
  7.     else {
  8.         if (n > 0 and n%10 >= (n/10)%10) return es_creixent(n/10);
  9.         return false;
  10.     }
  11. }
  12.  
  13. //Pre: Llegeix un natural
  14. //Post: Retorna cert si els digits sรณn creixents
  15. int main() {
  16.     int n;
  17.     cin >> n;
  18.     cout << es_creixent(n) << endl;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement