wes d2a2ba9e15 first commit | 4 yıl önce | |
---|---|---|
.. | ||
README.md | 4 yıl önce | |
code.cpp | 4 yıl önce | |
unitTest.cpp | 4 yıl önce |
by Matt tags: numbers, language_fundamentals, validation
A number is narcissistic when the sum of its digits, with each digit raised to the power of digits quantity, is equal to the number itself. 153 ➞ 3 digits ➞ 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 ➞ Narcissistic 84 ➞ 2 digits ➞ 8² + 4² = 64 + 16 = 80 ➞ Not narcissistic Given a positive integer n, implement a function that returns true if the number is narcissistic
A number is narcissistic when the sum of its digits, with each digit raised to the power of digits quantity, is equal to the number itself.
153 ➞ 3 digits ➞ 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 ➞ Narcissistic
84 ➞ 2 digits ➞ 8² + 4² = 64 + 16 = 80 ➞ Not narcissistic
Given a positive integer n
, implement a function that returns true
if the number is narcissistic, and false
if it's not.
isNarcissistic(8208) ➞ true
// 8⁴ + 2⁴ + 0⁴ + 8⁴ = 8208
isNarcissistic(22) ➞ false
// 2² + 2² = 8
isNarcissistic(9) ➞ true
// 9¹ = 9