Balanced numbers

In this exercise, we say that a natural number is balanced if the sum of
the digits in even positions is equal to the sum of the digits in odd
positions. For instance, 1463 and 48015 are balanced numbers.

Write a function that tells if a natural number @n@ is balanced or not.

Interface

+-------:+:---------------------------------------------+
| C++    |     bool is_balanced(int n);                 |
+--------+----------------------------------------------+
| C      |     int is_balanced(int n);                  |
+--------+----------------------------------------------+
| Java   |     public static boolean isBalanced(int n); |
+--------+----------------------------------------------+
| Python |     is_balanced(n)  # returns bool           |
+--------+----------------------------------------------+
|        |     is_balanced(n: int) -> bool              |
+--------+----------------------------------------------+

Observation

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

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:29:32.793Z

© Jutge.org, 2006–2026.
https://jutge.org
