跳到主要內容

【C#】輸入兩數求兩數最大值

 class Program
    {
        static void Main(string[] args)
        {
            int a, b, max;
            Console.Write ("please input a:");
                a=int.Parse (Console.ReadLine ());
                Console.Write("please input b:");
                b = int.Parse(Console.ReadLine());

                max = a; //設定最大值為第一數(a)//
           
            if (b > max) //當第二數(b)大於最大值時,最大值則由(b)取代//
                    max = b;
            Console .Write ("This Max is:");
                Console.WriteLine (max);
                Console.ReadKey();
        }
    }

留言

這個網誌中的熱門文章

【C#】輸入0-100的分數判斷成績等級

輸入0-100的分數 當分數大於90時,輸出A 當分數大於80-89時,輸出B 當分數大於70-79時,輸出A 當分數大於0-69時,輸出D   class Program     {         static void Main(string[] args)         {            string cls="";             Console.Write ("請輸入成績:");             string s1 = Console.ReadLine();             int a=int.Parse (s1);             if(a>=90)                      cls="A";             else                    if(a>=80)                           cls="B";             else                      if(a>=70)   ...

【VB.NET】撰寫簡易九九乘法表

程式碼範例: Module Module1     Sub Main()         For i As Integer = 1 To 9             For j As Integer = 2 To 9                 Console.Write("{0}*{1}={2}{3}", j, i, i * j, vbTab)             Next             Console.WriteLine()         Next         Console.ReadKey()     End Sub End Module 執行結果: