internal class Program
{
private static void Main(string[] args)
{
int[] ary = { 1, 2, 7, 3, 4};
int max = 0;
for(int i=0; i<ary.Length; i++)
{
if(i==0)
{
max = ary[i];
}
else
{
if (ary[i] > max)
{
max = ary[i];
}
}
}
Console.WriteLine("陣列內容:");
showArray(ary);
Console.WriteLine("陣列最大值為:" + max);
}
//顯示陣列內容
static void showArray(int[] ary)
{
for (int i=0; i<ary.Length; i++)
{
Console.Write(ary[i] + ",");
}
Console.WriteLine();
}
}
#C#