C# - 255 Characters.
int x=100;decimal k=0;while(x>0){k++;decimal d=k*k;string s=d.ToString("n").Replace(",","").Split('.')[0];int g=k.ToString().Length;int h=s.Length;if(k==d||(h!=g&&long.Parse(s.Substring(h-g))+long.Parse(s.Substring(0,h-g))==k)){Console.Write(k+" ");x--;}}
x is the number of Kaprekar numbers you wish the code to find. This has been tested in the range of 1 to 100 but should support a lot more than this. 100 numbers took two and a quarter hours to return although the first 50 only took about 1 second - things slowed down gradually after that.
Output:
1 9 45 55 99 297 703 999 2223 2728 4950 5050 7272 7777 9999 17344 22222 77778
82656 95121 99999 142857 148149 181819 187110 208495 318682 329967 351352 356643
390313 461539 466830 499500 500500 533170 538461 609687 643357 648648 670033
681318 791505 812890 818181 851851 857143 961038 994708 999999 4444444 4927941
5072059 5555556 9372385 9999999 11111112 13641364 16590564 19273023 19773073
24752475 25252525 30884184 36363636 38883889 44363341 44525548 49995000 50005000
55474452 55636659 61116111 63636364 69115816 74747475 75247525 80226927 80726977
83409436 86358636 88888888 91838088 94520547 99999999 234567901 332999667
432432432 567567568 667000333 765432099 999999999 1111111111 1776299581 2020202020
3846956652 3888938889 4090859091 4132841328 4756047561
Laid out this code is as follows;
int x = 100;
decimal k = 0;
while (x > 0)
{
k++;
decimal d = k * k;
string s = d.ToString("n").Replace(",", "").Split('.')[0];
int g = k.ToString().Length;
int h = s.Length;
if (k == d || (h != g && long.Parse(s.Substring(h - g)) + long.Parse(s.Substring(0, h - g)) == k) )
{
Console.Write(k + " "); x--;
}
}
I'd love to know if this can be shortened further.
n
up to at least 100. \$\endgroup\$