Quiz2_1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("103臺灣師範大學機電科技系物件導向程式設計_Quiz2");
int a, b, c;
for (int i = 1000; i < 1240; i++ )
{
b = i / 100;
c = i % 100;
/*Console.WriteLine("{0}", b);
Console.WriteLine("{0}", c);*/
if(i==((b * b)+(c * c)))
Console.WriteLine("{0}", i);
}
Console.ReadKey();
}
}
}
Quiz2_2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("103臺灣師範大學機電科技系物件導向程式設計_Quiz2_2");
int a, b, c, count=0;
int k;
for (int i = 1; i < 1000000; i++)
{
k = 0;
for (int j = 1; j < 1000000; j = j * 10)
{
k++;
if ((i / j) == 0)
{
count = (k - 1);
break;
}
}
a = i / 10000;
b = (i - a * 10000) / 100;
c = i % 100;
/*Console.WriteLine("{0}", count);
Console.WriteLine("{0}", a);
Console.WriteLine("{0}", b);
Console.WriteLine("{0}", c);*/
if (count == 1 || count == 2)
{
if (i == c)
Console.WriteLine("{0}", i);
}
else if (count == 3 || count == 4)
{
if (i == (b * b) + (c * c))
Console.WriteLine("{0}", i);
}
else if (count == 5 || count == 6)
{
if (i == (a * a * a) + (b * b * b) + (c * c * c))
Console.WriteLine("{0}", i);
}
}
Console.ReadKey();
}
}
}
沒有留言:
張貼留言