Program for Armstrong Numbers |
using System ; public class armstrongNumber { public void isArmstrong ( String n ) { char [ ] s = n . ToCharArray ( ) ; int size = s . Length ; int sum = 0 ; foreach ( char num in s ) { int temp = 1 ; int i = Int32 . Parse ( char . ToString ( num ) ) ; for ( int j = 0 ; j <= size - 1 ; j ++ ) { temp *= i ; } sum += temp ; } if ( sum == Int32 . Parse ( n ) ) { Console . WriteLine ( " True " ) ; } else { Console . WriteLine ( " False " ) ; } } public static void Main ( String [ ] args ) { armstrongNumber am = new armstrongNumber ( ) ; am . isArmstrong ( "153" ) ; am . isArmstrong ( "231" ) ; } }