c#程序设计求1-999之间的阿姆斯特朗数 10
展开全部
private string GetData()
{
string sResult = "";
int i = 1;
int j = 1;
while ((long)i < 1000)
{
if (i < Math.Pow(10, (j + 2)))
{
if ((int)Getresult(i, j) == i)
{
sResult += i.ToString() + Environment.NewLine;
}
}
else
{
j++;
}
i++;
}
return sResult;
}
private static int Getresult(int i, int j)
{
int result = 0;
for (int x = 0; x < i.ToString().Length; x++)
{
int te = Convert.ToInt32(i.ToString().Substring(x, 1));
result += (int)(Math.Pow(te, (j + 2)));
}
return result;
}
{
string sResult = "";
int i = 1;
int j = 1;
while ((long)i < 1000)
{
if (i < Math.Pow(10, (j + 2)))
{
if ((int)Getresult(i, j) == i)
{
sResult += i.ToString() + Environment.NewLine;
}
}
else
{
j++;
}
i++;
}
return sResult;
}
private static int Getresult(int i, int j)
{
int result = 0;
for (int x = 0; x < i.ToString().Length; x++)
{
int te = Convert.ToInt32(i.ToString().Substring(x, 1));
result += (int)(Math.Pow(te, (j + 2)));
}
return result;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询