121

(8 відповідей, залишених у C#, .NET)

using System;
using System.Collections;
using System.Collections.Generic;

namespace Armstrong
{
    class Program
    {
        public static void Main(string[] args)
        {                        
            List<int> listArmstron = new List<int>();
            int N = 0;
            int[] arrNum = {0,0,0,0};
            
            for (N = 100; N < 999; N++) {
                char[] arrCh = N.ToString().ToCharArray();
                arrNum = new int[arrCh.Length];
                
                for(int i=0;i<arrCh.Length;i++)
                    arrNum[i] = Int32.Parse(arrCh[i].ToString());
                
                Int32 Sum = 0;
                for(int i=0;i<arrNum.Length;i++) {
                    Sum +=  Convert.ToInt32(Math.Pow(arrNum[i],arrNum.Length));
                    //Console.Write("arr[{0}]={1},S={2}",i,arrNum[i],Sum);
                }
                
                                
                if(N == Sum) {
                    listArmstron.Add(N);
                    //Console.Write("N={0},Ch={1},Suma={2}",N,new String(arrCh),Sum);
                }
                
            }
            foreach (int e in listArmstron) {
                Console.Write("\n{0},",e);
            }
            Console.Write("\nPress any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}