Narcissistic NumberĀ is a number that is the sum of its own digits each raised to the power of the number of digits.
e.g.
153 = 13+53+33
1634 = 14+64+34+44
C code for finding whether given number isĀ Narcissistic Number or not.
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 |
#include<stdio.h> #include<math.h> int main(){ int a,n,d=0,m,sum=0; printf("\"Program To Check Whether It Is Narcissistic Or Not\" \n"); printf("Enter the number \n"); scanf("%d",&n); m=n; //for counting the number of digits in number while(m>0){ m=m/10; d++; } m=n; while(n>0){ a=n%10; sum=sum+pow(a,d); n=n/10; } if(sum==m) printf("Number is Narcissistic"); else printf("Number is not Narcissistic"); return 0; } |
Code provided by : Manoj