Machine Problem 5.7.
Write a program using two-‐dimensional arrays that determines the highest and lowest of the 12 input
values.
Sample input/output dialogue:
Enter twelve numbers: 13 15 20 13 35 40 16 18 20 18 20 19
The highest is: 40
The lowest is: 13
using System;
namespace twodim_maxmin
{
class Program
{
public static void Main(string[] args)
{
int i,j, max, min;
int [ , ] array = new int[4,3];
Console.WriteLine("Enter twelve numbers:");
for (i=0; i<4; i++)
for (j=0; j<3; j++)
array[i,j] = Convert.ToInt32(Console.ReadLine());
max = array[0,0];
min = array[0,0];
Console.WriteLine();
Console.WriteLine("Array: ");
for (i=0; i<4; i++)
{
for (j=0; j<3; j++)
{
Console.Write("{0} ", array[i,j]);
if (max < array[i,j])
max = array[i,j];
if (min > array[i,j])
min = array[i,j];
}
Console.WriteLine();
}
Console.WriteLine();
Console.WriteLine("The highest is: {0}", max);
Console.WriteLine("The lowest is: {0}", min);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Comments
Leave a comment