appblue4DS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace bai_4_day_so
{
public partial class Frmbai4 : Form
{
int[] a = new int[100];
int n;
public Frmbai4()
{
InitializeComponent();
}
private void txtbox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(((e.KeyChar >= '0')&&(e.KeyChar<='9'))
||(Convert.ToInt32(e.KeyChar)== 8)||(Convert.ToInt32(e.KeyChar) == 13))
{
e.Handled=false;
}
else
{
e.Handled = true;
}
}
private void btnnhap_Click(object sender, EventArgs e)
{
if (txtbox1.Text == " ")
{
MessageBox.Show("ban phải nhập n ", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtbox1.Focus();
return;
}
Random rnd = new Random();
n = int.Parse(txtbox1.Text);
for (int i = 0; i < n; i++)
{
a[i] = rnd.Next(1, 100);
lbldayso.Text += (" " + a[i].ToString());
}
btnnhap.Enabled=false;
}
private void btntinhs_Click(object sender, EventArgs e)
{
int tong = 0;
for (int i = 0; i < n; i++)
{
tong += a[i];
}
lbltong.Text=lbltong.Text + ": " + tong;
btntinhs.Enabled = false;
}
private void btnsapxep_Click(object sender, EventArgs e)
{
int tg;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (a[i] < a[j])
{
tg = a[j];
a[j] = a[i];
a[i] = tg;
}
for(int i=0;i<n;i++)
lblsapxep.Text = lblsapxep.Text + " " + Convert.ToString(a[i]);
lblsapxep.Enabled = false;
}
private void btnlamlai_Click(object sender, EventArgs e)
{
txtbox1.Text = "";
lbldayso.Text = "Day so: ";
lbltong.Text = "Tong day: ";
lblsapxep.Text = "Sap xep: ";
txtbox1.Focus();
btnnhap.Enabled = true;
btntinhs.Enabled = true;
btnsapxep.Enabled = true;
}
private void btnthoat_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
Bạn đang đọc truyện trên: AzTruyen.Top