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.
The answer to the question is available in the PDF file https://assignmentexpert.com/https://assignmentexpert.com/homework-answers/programming-answer-37471.pdf
Comments
Leave a comment