用C# 求二维数组的最大值、最小值
2个回答
2013-08-26
展开全部
伪代码,重在思想。int[][] intArr = 已经初始化的二维数组int max = int.MIN_VALUE;int min = int.MAX_VALUE;for (int i = 0; i < intArr.Length; i++){ for (int j= 0; j < intArr[0].Length;j++) { if (intArr[i][j] > max) { max = intArr[i][j]; } if (intArr[i][j] < min) { min = intArr[i][j]; } } Console.WriteLine("max = {0}, min = {1}",max,min);
}
}
2013-08-26
展开全部
using System;
public class Test
{
public static void Main(string[] args)
{
int[] num = new int[4];
int max,min;
for (int i = 0; i < num.Length; i )
{
num[i] = Convert.ToInt32(Console.ReadLine());
}
max = num[0];
min = num[0];
for (int i = 0; i < num.Length; i )
{
if (max < num[i])
max = num[i];
if (min > num[i])
min = num[i];
}
Console.WriteLine("最大值:" max);
Console.WriteLine("最小值:" min);
}
}
public class Test
{
public static void Main(string[] args)
{
int[] num = new int[4];
int max,min;
for (int i = 0; i < num.Length; i )
{
num[i] = Convert.ToInt32(Console.ReadLine());
}
max = num[0];
min = num[0];
for (int i = 0; i < num.Length; i )
{
if (max < num[i])
max = num[i];
if (min > num[i])
min = num[i];
}
Console.WriteLine("最大值:" max);
Console.WriteLine("最小值:" min);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询