namespace practice
{
class Test
{
static void Main(string[] args)
{
Console.WriteLine("ex.1\n");
int nfront;
int nbehind;
int temp = 0 , temp2=0;
int segment = 1;
int sum =0;
for (int i = 1000; i <= 9999; i++)
{
nfront =i / 100;
nbehind = i % 100;
if (i == Math.Pow(nfront, 2.0) + Math.Pow(nbehind, 2.0))
Console.WriteLine("{0}", i);
}
Console.WriteLine("==============我是分隔線===============");
Console.WriteLine("ex.2\n");
for (int i = 1; i <= 999999; i++)
{
temp = i; //處理次方
while (temp / 100 > 0)
{
segment++;//累計次方數
temp/=100;//Ex:5位數字除以100可除3次
} //處理次方
temp = i; //分割數字
for (int j = 1; j <= segment; j++) //設定<=次方數為中止條件
{
temp2 = temp % 100; //因為沒法直接"(int)Math.Pow((double)temp % 100, (double)segment)",所以需要第二個暫存"取尾數"
temp /= 100; //將取過尾數的第一暫存砍掉尾數
sum += (int)Math.Pow((double)temp2, (double)segment); //做相加
} //分割數字
if (i == sum) //判斷式
Console.WriteLine("{0}", i);
temp = 0;
sum = 0;
segment = 1;
}
Console.ReadKey();
}
}
}
2015年3月12日 星期四
[2015][Quiz][Week03] Quiz2 - 60373006H
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言