C # Combat--three numbers to find maximum (4 methods)

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;/** Compile a program * Enter three numbers from the keyboard * use the ternary operator (?:) to find out the maximum number. */namespacepi{classProgram {Static voidMain (string[] args)            {Int32 var_a, var_b, Var_c,max; Var_a=int.            Parse (Console.ReadLine ()); Var_b=int.            Parse (Console.ReadLine ()); Var_c=int.           Parse (Console.ReadLine ()); //-----------------1----------------------//if (var_a>var_b)//{            //max=var_a; //}            //else if (var_c>var_b)//    {            //Max=var_c; //    }            //else Max=var_b; //-----------------2--------------------//max = var_a; //if (Var_b > Max)//max = Var_b; //else if (Var_c > Max)//max = Var_c; //-------------3--------------//max = var_a > Var_b var_a:var_b; //max = max > Var_c max:var_c; //----------------4-----------------Max=var_a>var_b?var_a>var_c?var_a:var_c:var_b>var_c?Var_b:var_c; //------------5--------------------------Console.WriteLine ("First Number: {0}\n second number: {1}\n third number: {2}\n maximum: {3}\n", Var_a,var_b,var_c,max);        Console.readkey (); }    }}

C # Combat--three numbers to find maximum (4 methods)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.