In recreational number theory, a narcissistic number (also known as a pluperfect digital invariant (PPDI), an Armstrong number (after Michael F. Armstrong) or a plus perfect number) is a number that is the sum of its own digits each raised to the power of the number of digits. This definition depends on the base b of the number system used, e.g., b = 10 for the decimal system or b = 2 for the binary system.
// Find Narcissistic number of 3 digits
#include<stdio.h>
int main()
{
int i, a, b, c;
printf("Narcissistic number of 3 digits are :\n");
for (i = 100; i <= 999; ++i)
{
a = i / 100;
b = (i / 10) % 10;
c = i % 10;
if (i == a*a*a + b*b*b + c*c*c)
printf("%5d",i);
}
printf("\n");
return 0;
}
#include<stdio.h>
void main()
{
int i, a, b, c;
printf("Narcissistic number of 3 digits are :\n");
for (i = 100; i <= 999; ++i)
{
a = i * 0.01;
b = 10 * (0.01 * i - a);
c = i - 100 * a - 10 * b;
if (i == a*a*a + b*b*b + c*c*c)
printf("%5d",i);
}
printf("\n");
}
Output:
Narcissistic number of 3 digits are :
153 370 371 407