1.输出100-999之间的水仙花数。水仙花数是指其各位数字立方和等于该数本身的数,如153=1^3+5^3+3^3。
代码如下:
<span style="font-family:SimSun;font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 水?仙¨¦花¡§数ºy
{
class Program
{
static void Main(string[] args)
{
int a, b, c, x,s;
for (x = 100; x <= 999; x++)
{
a = x / 100;
b = x / 10 % 10;
c = x % 10;
s = a * a * a + b * b * b + c * c * c;
if (s == x)
{
Console.WriteLine(x);
}
}
Console.ReadLine();
}
}
}</span>
运行结果:
2.找出1000以内的完全数。完全数:该数的因子(不包含本身)之和等于其本身。如28是完全数,因为28=1+2+4+7+14
代码如下:
<span style="font-family:SimSun;font-size:18px;">using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace Wanshu
{
class Program
{
static void Main(string[] args)
{
int s = 0;
int a = 0;
int i, j;
Console.WriteLine("1000以°?内¨²的Ì?完ª¨º数ºy为a:êo");
for (i = 1; i <= 1000; i++)
{
s = 0;
for (j = 1; j <= i/2; j++)
{
if (i % j == 0 && i != j)
{
s += j;
}
}
if (s == i)
{
Console.WriteLine("{0}\t", i);
}
}
Console.ReadLine();
}
}
}</span>
运行结果:
3.找出2~999之间所有的同构数。所谓同构数是指该数出现在它的平方数的右边。如5、6、25等。
代码入下:
<span style="font-family:SimSun;font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 同ª?构1数ºy
{
class Program
{
static void Main(string[] args)
{
int x, i,k = 10;
for (i = 2; i <= 999; i++)
{
x = i * i;
if (i == k)
{
k = k * 10;
}
if (x % k == i)
{
Console.WriteLine("\t"+i);
}
}
Console.ReadLine();
}
}
}</span>
运行结果: