پیدا کردن بزرگترین عدد در آرایه با تابع
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
FindBigInteger
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
int
i = 0;
int
[] araye =
new
int
[count];
const
int
count = 5;
int
TEMP;
private
void
button1_Click(
object
sender, EventArgs e)
{
label1.Text +=
""
+ test(araye);
}
private
void
textBox1_KeyPress(
object
sender, KeyPressEventArgs e)
{
if
(e.KeyChar ==
'\r'
)
{
araye[i] = Convert.ToInt32(textBox1.Text);
i++;
if
(i < count)
textBox1.Text =
""
;
else
{
MessageBox.Show(
"Enough"
);
i = 0;
}
}
}
public
int
test(
int
[] Array)
{
int
max = Array[0];
for
(
int
s = 0; s < Array.Length; s++)
{
if
(max < Array[s])
max = Array[s];
}
return
max;
}
}
}
یکشنبه یکم اردیبهشت ۱۳۹۲ | 18:37