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)
{
int num;
int ans;
for(num=1000;num<=9999;num++)
{
int a = num % 100;
int b = num / 100;
if (num==(a*a)+(b*b))
Console.WriteLine("Answer = {0}",num);
}
Console.ReadKey();
}
}
}
Quiz2_2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace week3
{
class Program
{
static void Main(string[] args)
{
int n;
int a = 0;
int temp;
for (n = 1000; n <= 999999; n++)
{
double sum = 0;
double p = 0;
temp = n;
while (temp != 0)
{
temp = temp / 100;
p++;
}
temp = n;
while (temp != 0)
{
a = temp % 100;
sum += Math.Pow((double)a, (double)p);
temp /= 100;
}
if (sum == n)
{
Console.WriteLine("Anwer = {0}", sum);
}
}
Console.Read();
}
}
}
沒有留言:
張貼留言