
展开全部
三个数的最大值和最小值C#代码参考下面。
(利用了两种不同的实现方案,你可以选择自己适合。)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ts01
{
class Program
{
//计算三个整数的最大值
static int Max3(int a, int b, int c)
{
int maxValue = a;
if(maxValue < b)
{
maxValue = b;
}
if(maxValue < c)
{
maxValue = c;
}
return maxValue;
}
//计算三个整数的最小值
static int Min3(int a, int b, int c)
{
int minValue = a;
minValue = Math.Min(minValue, b);
minValue = Math.Min(minValue, c);
return minValue;
}
static void Main(string[] args)
{
int a = 10, b = 20, c = 30;
Console.WriteLine("10, 20, 30 's max value is:{0}", Max3(a, b, c));
Console.WriteLine("10, 20, 30 's min value is:{0}", Min3(a, b, c));
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询