c#public class Program{ public static int[] GenerateDivisors(int n) { if (n <= 0) { return null; } List<int> divisors = new List<int>(); for (int i = 1; i <= Math.Sqrt(n); i++) { if (n % i == 0) { divisors.Add(i); if (i != n / i) { divisors.Add(n / i); } } } divisors.Sort(); divisors.Remove(n); return divisors.ToArray(); } public static int GetSumOfDivisors(int[] x) { int total = 0; for (int i = 0; i < x.Length; i++) { total += x[i]; } return total; } private static void GetNextNumber(int x) { var values = GenerateDivisors(x); var sum = GetSumOfDivisors(values); while (true) { Console.WriteLine(x); if (x == 0) { return; } GetNextNumber(sum); } } public static void Main(string[] args) { GetNextNumber(18); }}
C#C#public static void Main(string[] args) { Console.WriteLine(IsPalindrome(121)); } private static bool IsPalindrome(int x) { var input = (x + "").ToCharArray(); return input.Equals(Reverse(input)); } private static char[] Reverse(char[] input) { char[] output = new char[input.Length]; int index = 0; for (int i = input.Length - 1; i >= 0; i--) { output[index] = input[i]; index++; } return output; }