using System; class PowerOfThree { // Entry Point public static void Main() { Console.WriteLine("Enter number: "); int userInput = Convert.ToInt32(Console.ReadLine()); if (CheckMultiple(userInput) != 0) Console.Write("\n{0} is a multiple of 3.", userInput); else Console.Write("\n{0} is not a multiple of 3.", userInput); Console.Read(); } static int CheckMultiple(int n) { int odd = 0, even = 0; if (n < 0) n = -n; if (n == 0) return 1; if (n == 1) return 0; while (n != 0) { if ((n & 1) != 0) odd++; n = n >> 1; if ((n & 1) != 0) even++; n = n >> 1; } return CheckMultiple(Math.Abs(odd - even)); } }
Output