求水仙花数用了另一种方法,但开始计算立方的时候被计算的数就变了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _042_练习一
{
class Program
{
static void Main()
{
int sum = 0;
for (int i = 100; i < 101; i++)
{
string str =Convert.ToString(i);
for (int s = 0; s < str.Length; s++)
{
int res = str[s]* str[s]* str[s];
sum += res;
if (sum == i)
{
Console.WriteLine(i);
}
}
}
Console.ReadKey();
}
}
}
int res = str[s]* str[s]* str[s]; 这里str[s]就变成了49,这之前和之后我输出了str[s]的值都是1
字符'1'的ASCII值是49