You are viewing a single comment's thread. Return to all comments →
C# Solution
public static void kaprekarNumbers(int p, int q) { string numbers = ""; for(double i = p; i <= q; i++) if(IsNumberKaprekar(i)) numbers += i + " ";
if(numbers.Length == 0) Console.WriteLine("INVALID RANGE"); else Console.WriteLine(numbers); } public static bool IsNumberKaprekar(double num) { string square = Convert.ToString(num*num); int d = square.Length / 2; double sum = 1; if(square.Length > 1) sum = Convert.ToDouble(square.Substring(0, d)) + Convert.ToDouble(square.Substring(d)); if(sum == num) return true; else return false; }
Seems like cookies are disabled on this browser, please enable them to open this website
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →
C# Solution
public static void kaprekarNumbers(int p, int q) { string numbers = ""; for(double i = p; i <= q; i++) if(IsNumberKaprekar(i)) numbers += i + " ";