2015年3月12日 星期四

[2015][Quiz][Week03] Quiz02 - 40173027H

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();
        }
    }
}

[2015][Quiz][Week03] Quiz02 - 40173037H

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _40173037H_quiz2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("========第一題==========");
            int i;
            int a,a_,b,b_,c,d;
            for (i = 1000; i <= 9999; i++)
            {
                a = i / 100; b = i % 100;
                
                if (i == (a*a+b*b))
                    Console.WriteLine("{0}", i);
            }
            Console.WriteLine("================第二題===============");
            int j;
           
            for (j = 1; j <= 999999; j++)
            {
                if (j <= 99)
                { 
                    if (j==(j%100))
                    Console.WriteLine("{0}",j);
                    
                }
                else if((j>99)&&(j<=9999))
                {
                    if (j == (j / 100) * (j / 100) + (j % 100) * (j % 100))
                        Console.WriteLine("{0}", j);


                }
                else if ((j > 9999) && (j <= 999999))
                {
                    if (j == ((j / 10000) * (j / 10000) * (j / 10000) + ((j % 10000) / 100) * ((j % 10000) / 100) * ((j % 10000) / 100) + ((j % 10000) % 100) * ((j % 10000) % 100) * ((j % 10000) % 100))) 
                    Console.WriteLine("{0}",j);
                }
            }
                Console.Read();
        }
    }
}

Test

//可將程式碼放於此處,請至文章的html模式編輯