zoukankan      html  css  js  c++  java
  • c# 求两个数中最大的值

    1、三元运算符:

     1   class Program
     2     {
     3         static void Main(string[] args)
     4         {
     5           int max= NumMAX(10,15);
     6             Console.WriteLine("最大数:{0}",max);
     7             Console.ReadKey();
     8         }
     9    /// <summary>
    10         /// 两个数中最大的值
    11         /// </summary>
    12         /// <param name="p1"></param>
    13         /// <param name="p2"></param>
    14         /// <returns></returns>
    15         private static int NumMAX(int p1, int p2)
    16         {
    17            return p1 > p2 ? p1 : p2;
    18         }
    19 }
    View Code

    2、if条件判断:

     1 class Program
     2     {
     3         static void Main(string[] args)
     4         {
     5           int max= NumMAX(10,15);
     6             Console.WriteLine("最大数:{0}",max);
     7             Console.ReadKey();
     8         }
     9    /// <summary>
    10         /// 两个数中最大的值
    11         /// </summary>
    12         /// <param name="p1"></param>
    13         /// <param name="p2"></param>
    14         /// <returns></returns>
    15         private static int NumMAX(int p1, int p2)
    16         {
    17               if (p1>p2)
    18             {
    19                 return p1;
    20             }
    21             return p2;
    22         }
    23 }
    View Code

    3、Math函数:

     1 class Program
     2     {
     3         static void Main(string[] args)
     4         {
     5           int max= NumMAX(10,15);
     6             Console.WriteLine("最大数:{0}",max);
     7             Console.ReadKey();
     8         }
     9    /// <summary>
    10         /// 两个数中最大的值
    11         /// </summary>
    12         /// <param name="p1"></param>
    13         /// <param name="p2"></param>
    14         /// <returns></returns>
    15         private static int NumMAX(int p1, int p2)
    16         {
    17            return Math.Max(p1, p2);
    18         }
    19 }
    View Code
  • 相关阅读:
    c中NULL,'\0'和0之间的区别. (the difference between NULL,'\0' and 0 in c)
    python 解析xml文件python parse xml.
    mysql升级 ,MySQL Error: #1558 Column count of mysql.proc is wrong. Expected 20, found 16.
    文献随笔15
    文献笔记11
    文献笔记16
    文献笔记13
    文献笔记17
    文献笔记20
    文献笔记19
  • 原文地址:https://www.cnblogs.com/zlp520/p/3551636.html
Copyright © 2011-2022 走看看