# Narcissistic Number C Program

## 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.**

#### Example:

**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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include<stdio.h> int power(int c, int d) { int pow = 1; int count = 1; while(count <= d) { pow = pow*c; count++; } return pow; } int main() { int num1, digit, temp, rem, sum = 0; printf("\n Enter a number:\t"); scanf("%d", &num1); printf("\n Enter Number of Digits:\t"); scanf("%d", &digit); temp = num1; while(temp != 0) { rem = temp%10; sum = sum + power(rem, digit); temp = temp/10; } if(sum == num1) printf("\n%d is a Narcissistic Number\n", num1); else printf("\n%d is not a Narcissistic Number\n", num1); return 0; } |

#### Method 2: Check Narcissistic Number with For Loop in C Program

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include<stdio.h> int power(int c, int d) { int pow = 1; int count = 1; while(count <= d) { pow = pow*c; count++; } return pow; } int main() { int num1, digit, temp, rem, sum = 0; printf("\nEnter a number:\t"); scanf("%d", &num1); printf("\nEnter Number of Digits:\t"); scanf("%d", &digit); for(temp = num1; temp != 0;) { rem = temp%10; sum = sum + power(rem, digit); temp = temp/10; } if(sum == num1) printf("\n%d is a Narcissistic Number\n", num1); else printf("\n%d is not a Narcissistic Number\n", num1); return 0; } |

#### Output

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.

Thanks for such a definitive guide!

You’re welcome. Glad that you liked it.

Thanks.

Excellent Explanation. Thanks.

Hey instead of taking digits from user, use on counter and get digits… it will help to generate armstrong/narcissistic number… Cheers…

Yes Ashish! We can use even that approach to get the digits! Thanks for Information anyway! 🙂

How can we count the Number of Digits in the Input given by the User?

It is easy. Check this

C Program to Count Number of Digits in an Integer.So, this is basically like an Armstrong Number with more than 3 digits, right?

This seems to be similar to Armstrong Number. What I could sense is that when an Armstrong Number with 4 digits or more needs to be calculated then it is called as Narcissiatic Number, right?

So, finally I have found the 4 digit armstrong number c program. Thanks to the creator of this code.

This is so similar to Armstrong Number.

Very good explanation