Question #37471

Exercise 2: Narcissistic Number

A narcissistic number is a positive integer which is equal to its digits sum raised to the number

of digits in the integer. For example the integer 153 has three digits, then 1

3

+ 5

= 1 + 125

+ 27 = 153 and so 153 is a narcissistic number, while 351 is 3

3

+ 5

3

+ 1

3

= 27 + 125 + 1 = 153

≠ 351. The numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 407, 1634, 8208, 24678051 are all narcissistic

numbers.

Define the function: bool isNarcissistic(int)

Write a main function on which reads a positive integer, calls the function isNarcissistic( ), and

prints whether the integer is a narcissistic number or not.

A narcissistic number is a positive integer which is equal to its digits sum raised to the number

of digits in the integer. For example the integer 153 has three digits, then 1

3

+ 5

= 1 + 125

+ 27 = 153 and so 153 is a narcissistic number, while 351 is 3

3

+ 5

3

+ 1

3

= 27 + 125 + 1 = 153

≠ 351. The numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 407, 1634, 8208, 24678051 are all narcissistic

numbers.

Define the function: bool isNarcissistic(int)

Write a main function on which reads a positive integer, calls the function isNarcissistic( ), and

prints whether the integer is a narcissistic number or not.

Expert's answer

## Comments

## Leave a comment