Increasing numbers P35537


Statement
 

pdf   zip   main.cc   main.c   main.java   main.py

html

In this exercise, we say that a natural number is increasing if every digit is less than or equal to the digit which is on its right (if any).

Write a recursive function that tells if a natural number n is increasing or not.

Interface

C++
bool is_increasing(int n);
C
int is_increasing(int n);
Java
public static boolean isIncreasing(int n);
Python
is_increasing(n) # returns bool
 
is_increasing(n: int) -> bool

Observation You only need to submit the required procedure; your main program will be ignored.

Public test cases
  • Input/Output

    is_increasing(123378) → true
    is_increasing(125433) → false
    is_increasing(7) → true
  • Information
    Author
    Jordi Petit
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C C++ Java Python
    User solutions
    C C++ Java Python