using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int max = 0;
private void button1_Click(object sender, EventArgs e)
{
int[] a = {5,4,3,2,1};
for (int i = 0; i <= 4; i++)
{
if (a[i] > max)//判斷a[i](初值為5)是否大於max(初值為0)
{
max = a[i];//若是則將a[i]的值給max
}
}
listBox1.Items.Add(max);//列印出陣列中的最大值
}
}
}
留言列表