2 Ways To Check A Narcissistic Number in C Programming
Learn How To Find if a Number is a Narcissistic Number or not in C Programming Language. It is important that we should know How A For Loop Works before getting further with the C Program Code.
What is a Narcissistic Number?
If the Sum of Digits of a Number raised to the power of the number of digits is equal to the Number/Integer, then it is a Narcissistic Number. It is similar to an Armstrong Number.
Three Digit Narcissistic Integer:
153 = (1 * 1 * 1) + (5 * 5 * 5) + (3 * 3 * 3)
Four Digit Narcissistic Number:
8208 = (8 * 8 * 8 * 8) + (2 * 2 * 2 * 2) + (0 * 0 * 0 * 0) + (8 * 8 * 8 * 8)
This program takes every individual digit from the Integer and calculates the digit raised to the power of the number of digits in the Integer. Adding these powers of every digits and then comparing it with the Integer. If Sum is equal to the Integer, then it is a Narcissistic Number.
Method 1: Check Narcissistic Number with While Loop in C Program
Method 2: Check Narcissistic Number with For Loop in C Program
In case you get any compilation errors in this C Program To Find Narcissistic Numbers or you have any doubt about it, let us know about it in the comment section below.