Narcissistic number | C # program for checking of Narcissistic number ; Traversing through the string ; Since ascii value of numbers starts from 48 so we subtract it from sum ; Converting string to integer ; Comparing number and sum ; Driver Code
using System ; class GFG { static string getResult ( string st ) { int sum = 0 ; int length = st . Length ; for ( int i = 0 ; i < length ; i ++ ) { sum = sum + ( int ) Math . Pow ( st [ i ] - '0' , length ) ; } int number = int . Parse ( st ) ; if ( number == sum ) return " yes " ; else return " no " ; } public static void Main ( string [ ] args ) { string st = "153" ; Console . Write ( getResult ( st ) ) ; } }