laptrinh

 Đề 1



Đề 2: a)
 b)
Đề 3 : a)
b)

đề 4: a) console
f(x)={căn x+1 nếu x>= -1 , x+sinx nếu x <-1
b)

Đề 6 : a)console
S= 1+1/2+1/3+…+1/n
b)
đề 7 : a) console : b) tìm phần tử lớn nhất trong dãy . c) sắp xếp các phần tử trong dãy theo thứ tự tăng dần . D) tính tổng các phần tử trong dẫy
b)
Đề 8 :a) console : f(x) = {căn x-2 nếu x>= 2 và 2+e^x nếu x<2
b)
đề 11: a)

b)

đề 12: console
f(x) = {2x+1 nếu x<=0 và 2cosx – 2^x nếu 0<x<2 và căn x-2 nếu x>= 2
b)
đề 16: a) console a) nhấp n . B) hiển thị mảng theo thứ tự tang dần . C) nhấp số nguyên x từ bàn phím. Kiểm tra xem trong mảng có pt nào = x ko . D) tìm phần tử có giá trị lớn nhất trong mảng
b)

đề 17: a) console
-nhập n , - tìm phần tử lớn nhất trên mỗi hang ,-đếm số phần tử dương chẵn trong ma trân,-tính tổng các phần tử trong ma trận
b)
Đề 18 : a) -
b)
đề 20: a)
b)
MessageBox.Show("Bạn có chắc muốn thoát không?", "Error",MessageBoxButtons.YesNoCancel); Application.Exit();
Đề 1.
namespace Đề_1_bài_1
{
    class Program
    {
        static void Main(string[] args)
        {
            float x, f;
            Console.Write("Nhap x: ");
            bool kt = float.TryParse(Console.ReadLine(), out x);
            while (!kt)
            {
                Console.Write("Hay nhap lai x: ");
                kt = float.TryParse(Console.ReadLine(), out x);
            }
            if (x < 0) f = (float)Math.Sqrt(2 * x * x + 3);
            else if (x > 1) f = x + 5;
            else f = (float)Math.Pow(3, x) + (float)Math.Cos(x);
            Console.WriteLine("Gia tri ham so f voi gia tri x = {0} la: {1}", x, f);
            Console.ReadLine();
        }
    }
}
namespace Đề_1_bài_2
{
    public partial class Form1 : Form
    {
        int n;
        int[] A;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            n = int.Parse(textBox1.Text);
            A = new int[n];
            int i = 0;
            while (i < n)
            {
                string s = Interaction.InputBox("Nhập A[" + i.ToString() + "]", "Nhập phần tử", "");
                try
                {
                    A[i] = int.Parse(s);
                    textBox2.Text += s + "   ";
                    i++;
                }
                catch
                {
                    MessageBox.Show("Dữ liệu nhập không đúng");
                }
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0) textBox3.Text = A.Max().ToString();
            else textBox3.Text = A.Average().ToString();
        }
    }
}

Đề 2
namespace Đề_2_bài_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                listBox1.Items.Add(textBox1.Text);
                textBox1.Clear();
                textBox1.Focus();
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1) listBox1.Items.RemoveAt(listBox1.SelectedIndex);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                listBox2.Items.Add(listBox1.SelectedItem);
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (listBox2.SelectedIndex != -1)
            {
                listBox1.Items.Add(listBox2.SelectedItem);
                listBox2.Items.RemoveAt(listBox2.SelectedIndex);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            foreach (string item in listBox1.Items)
                listBox2.Items.Add(item);
            listBox1.Items.Clear();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            foreach (string item in listBox2.Items)
                listBox1.Items.Add(item);
            listBox2.Items.Clear();
        }
    }
}



namespace Đề_2_bài_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            int n = int.Parse(textBox1.Text);
            int m = int.Parse(textBox2.Text);
            int a = n;
            int b = m;
            int c = a % b;
            while (c != 0)
            {
                a = b;
                b = c;
                c = a % b;
            }
            if (e.NewValue == CheckState.Checked)
            {
                richTextBox1.Clear();
                if (checkedListBox1.GetItemChecked(0) == true || checkedListBox1.SelectedIndex == 0) richTextBox1.Text += "UCLN =" + b.ToString() + Environment.NewLine;
                if (checkedListBox1.GetItemChecked(1) == true || checkedListBox1.SelectedIndex == 1) richTextBox1.Text += "BCNN =" + (m * n / b).ToString() + Environment.NewLine;
                if (checkedListBox1.GetItemChecked(2) == true || checkedListBox1.SelectedIndex == 2) richTextBox1.Text += "Số lớn nhất =" + Math.Max(m, n).ToString() + Environment.NewLine;
            }
            else
            {
                richTextBox1.Clear();
                if (checkedListBox1.GetItemChecked(0) == true && checkedListBox1.SelectedIndex != 0) richTextBox1.Text += "UCLN =" + b.ToString() + Environment.NewLine;
                if (checkedListBox1.GetItemChecked(1) == true && checkedListBox1.SelectedIndex != 1) richTextBox1.Text += "BCNN =" + (m * n / b).ToString() + Environment.NewLine;
                if (checkedListBox1.GetItemChecked(2) == true && checkedListBox1.SelectedIndex != 2) richTextBox1.Text += "Số lớn nhất =" + Math.Max(m, n).ToString() + Environment.NewLine;
            }
        }
    }
}

Đề 3.
namespace Đề_3_bài_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                checkedListBox1.Items.Add(textBox1.Text);
                textBox1.Clear();
                textBox1.Focus();
            }
            else MessageBox.Show("Hãy nhập dữ liệu");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (checkedListBox1.SelectedIndex != -1) checkedListBox1.Items.Remove(checkedListBox1.SelectedItem);
            else MessageBox.Show("Chưa chọn học phần để xóa");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            checkedListBox1.Items.Clear();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
        }

        private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.NewValue == CheckState.Checked) listBox1.Items.Add(checkedListBox1.SelectedItem.ToString());
            else listBox1.Items.Remove(checkedListBox1.SelectedItem.ToString());
        }
    }
}



namespace Đề_3_bài_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
            button2.Enabled =false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            float a, b;
            bool kt1 = float.TryParse(textBox1.Text, out a);
            bool kt2 = float.TryParse(textBox2.Text, out b);
            if (kt1 && kt2)
            {
                MessageBox.Show("Dữ liệu nhập vào hợp lệ");
                button2.Enabled = true;
            }
            else
            {
                MessageBox.Show("Dữ liệu nhập vào không hợp lệ");
                if (!kt1) textBox1.Focus();
                else textBox2.Focus();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label5.Visible = true;
            float a = float.Parse(textBox1.Text);
            float b = float.Parse(textBox2.Text);
            if (a == 0)
                if (b == 0) label5.Text = "Kết quả: Phương trình đúng với mọi x";
                else label5.Text = "Kết quả: Phương trình vô nghiệm";
            else label5.Text = "Kết quả: Phương trình có nghiệm x = " + (-b / a).ToString();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            button2.Enabled = false;
        }
    }
}

Đề 4
namespace Đề_4_bài_1
{
    class Program
    {
        static void Main(string[] args)
        {
            float x, f;
            bool kt;
            Console.Write("Nhap x: ");
            kt = float.TryParse(Console.ReadLine(), out x);
            while (!kt)
            {
                Console.Write("Hay nhap lai x: ");
                kt = float.TryParse(Console.ReadLine(), out x);
            }
            if (x < -1) f = (float)(x + Math.Sin(x));
            else f = (float)Math.Sqrt(x + 1);
            Console.WriteLine("Gia tri cua ham so f voi x = {0} la: {1} ", x, f);
            Console.ReadLine();
        }
    }
}
namespace Đề_4_bài_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                try
                {
                    int n = int.Parse(textBox1.Text);
                    button1.Enabled = true;
                    button3.Enabled = true;
                }
                catch
                {
                    MessageBox.Show("Dữ liệu nhập vào không đúng", "Thông báo");
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(textBox1.Text);
            textBox1.Clear();
            textBox1.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1) listBox1.Items.Remove(listBox1.SelectedItem);
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1) button2.Enabled = true;
            else button2.Enabled = false;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int tong = 0;
            foreach (string item in listBox1.Items)
            {
                tong += int.Parse(item);
            }
            label2.Text = "Tổng các phần tử trong dãy là " + tong.ToString();
            label2.Visible = true;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có chắc chắn muốn thoát","Thông báo",MessageBoxButtons.YesNo))
                this.Close();
        }
    }
}
Đề 6.
namespace Bài_1_đề_6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            float s= 0;
            bool kt = false;
            Console.Write("Nhap n: ");
            kt = int.TryParse(Console.ReadLine(), out n);
            while (!kt)
            {
                Console.Write("Hay nhap lai n: ");
                kt = int.TryParse(Console.ReadLine(), out n);
            }
            for (int i = 1; i <= n; i++) s += (float)1 / i;
            Console.WriteLine("Gia tri bieu thuc s voi n = {0} la: {1}", n, s);
            Console.ReadLine();
        }
    }
}
namespace Bài_2_đề_6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            float a, b;
            bool kt1 = float.TryParse(textBox1.Text, out a);
            bool kt2 = float.TryParse(textBox2.Text, out b);
            if (kt1 && kt2)
            {
                MessageBox.Show("Dữ liệu nhập vào hợp lệ");
                button2.Enabled = true;
            }
            else
            {
                button2.Enabled = false;
                MessageBox.Show("Dữ liệu nhập vào không đúng");
                if (!kt1) textBox1.Focus();
                if (!kt2) textBox2.Focus();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int a = int.Parse(textBox1.Text);
            int b = int.Parse(textBox2.Text);
            label4.Visible = true;
            if (a == 0)
                if (b <= 0) label4.Text = "Kết quả:  Bất phương trình vô nghiệm";
                else label4.Text = "Kết quả:  Bất phương trình đúng với mọi x";
            else
            {
                float c =(float)-b / a;
                if (a > 0) label4.Text = "Kết quả:  Bất phương trình có nghiệm x >" + c.ToString();
                else label4.Text = "Kết quả:  Bất phương trình có nghiệm x <" + c.ToString();
            }
        }
    }
}

Đề 7
namespace Đề_7_bài_1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Nhap n: ");
            int n = int.Parse(Console.ReadLine());
            int[] A = new int[n];
            for (int i = 0; i < n; i++)
            {
                Console.Write("Nhap A[{0}]:", i);
                A[i] = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("Day so nguyen da nhap la:");
            for (int i = 0; i < n; i++) Console.Write("    {0}",A[i]);
            Console.WriteLine();
            Console.WriteLine("Phan tu lon nhat trong day la: {0}", A.Max());
            Array.Sort(A);
            Console.WriteLine("Mang sau khi sap xep theo thu tu tang dan la:");
            for (int i = 0; i < n; i++) Console.Write("    {0}", A[i]);
            Console.WriteLine();
            Console.WriteLine("Tong cac phan tu trong day la: {0}", A.Sum());
            Console.ReadLine();
            }
    }
}

namespace Đề_7_bài_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            int n;
            bool kt = int.TryParse(textBox1.Text, out n);
            if (kt)
            {
                int tong = 0;
                while (n != 0)
                {
                    tong += n % 10;
                    n = n / 10;
                }
                label2.Text = "Tổng các chữ số của số của " + textBox1.Text + " là: " + tong.ToString();
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            int n = int.Parse(textBox1.Text);
            float tong = 0;
            for (int i = 1; i <= n; i++)
                tong += (float)1 / i;
            if (n > 2)
                label2.Text = "1 + 1/2 + ... + 1/" + n.ToString() + "=" + tong.ToString();
            else if (n == 2) label2.Text = "1 +1/2 = 3/2";
            else if (n == 1) label2.Text = "1 = 1";
        }
    }
}

Đề 8.
namespace Đề_8_bài_1
{
    class Program
    {
        static void Main(string[] args)
        {
            float x, f;
            Console.Write("Nhap x: ");
            bool kt = float.TryParse(Console.ReadLine(), out x);
            while (!kt)
            {
                Console.Write("Nhap lai x: ");
                kt = float.TryParse(Console.ReadLine(), out x);
            }
            if (x < 2) f = 2 + (float)Math.Exp(x);
            else f = (float)Math.Sqrt(x - 2);
            Console.WriteLine("Gia tri ham so f voi x = {0} la {1}", x, f);
            Console.ReadLine();
        }
    }
}

namespace Đề_8_bài_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                button2.Enabled = true;
                float a = float.Parse(textBox1.Text);
                float b = float.Parse(textBox2.Text);
                float c = float.Parse(textBox3.Text);
            }
            catch
            {
                MessageBox.Show("Dữ liệu nhập vào không đúng");
            }

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            float a = float.Parse(textBox1.Text);
            float b = float.Parse(textBox2.Text);
            float c = float.Parse(textBox3.Text);
            float delta = b * b - 4 * a * c;
            if (delta < 0) textBox4.Text = "Phương trình vô nghiệm";
            else if (delta == 0) textBox4.Text = "Phương trình có nghiệm kép x = " + (-b / 2 / a).ToString();
            else textBox4.Text = "Phương trình có hai nghiệm x1 =" + ((-b - Math.Sqrt(delta)) / 2 / a).ToString() + " ; x2= " + ((-b + Math.Sqrt(delta)) / 2 / a).ToString();
        }
    }
}

Đề 11.
namespace Đề_11_bài_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
            try
            {
                int n = int.Parse(textBox1.Text);
            }
            catch
            {
                MessageBox.Show("Dữ liệu nhập vào không đúng", "Nhập lại");
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int n = int.Parse(textBox1.Text);
            string[] A = new string[100];
            int tg;
            int q = int.Parse(comboBox1.SelectedItem.ToString());
            label4.Text = "Kết quả chuyển đổi số " + n.ToString() + " ở hệ 10 về hệ đếm cơ số " + q.ToString() + " là:";
            int i = 0;
            while (n != 0)
            {
                tg = n % q;
                n = n / q;
                i++;
                switch (tg)
                {
                    case 10: A[i] = "A"; break;
                    case 11: A[i] = "B"; break;
                    case 12: A[i] = "C"; break;
                    case 13: A[i] = "D"; break;
                    case 14: A[i] = "E"; break;
                    case 15: A[i] = "F"; break;
                    default: A[i] = tg.ToString(); break;
                }
            }
            for (int j = i; j >= 0; j--)
                label4.Text += A[j];

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có thực sự muốn thoát","Thông báo",MessageBoxButtons.YesNo)) this.Close();
        }
    }
}
namespace Đề_11_bài_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label3.Visible = true;
            int ts = int.Parse(textBox1.Text);
            int ms = int.Parse(textBox2.Text);
            int a = ts;
            int b = ms;
            int c = a % b;
            while (c != 0)
            {
                a = b;
                b = c;
                c = a % b;
            }
            label3.Text = "Phân số sau khi rút gọn là: " + (ts / b).ToString() + "/" + (ms / b).ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label3.Visible = true;
            int ts = int.Parse(textBox1.Text);
            int ms = int.Parse(textBox2.Text);
            label3.Text = "Giá trị phân số = " + ((float)ts / ms).ToString();
        }
    }
}

Đề 12.
namespace Đề_12.Bài_1
{
    class Program
    {
        static void Main(string[] args)
        {
            float x, f;
            Console.Write("Nhap x: ");
            bool kt = float.TryParse(Console.ReadLine(),out x);
            while (!kt)
            {
                Console.Write("Nhap lai x: ");
                kt = float.TryParse(Console.ReadLine(), out x);
            }
            if (x <= 0) f = 2 * x + 1;
            else if (x >= 2) f = (float)Math.Sqrt(x - 2);
            else f = 2 * (float)Math.Cos(x) - (float)Math.Pow(2, x);
            Console.WriteLine("Gia tri ham so f voi gia tri x = {0} la: {1}", x, f);
            Console.ReadLine();
        }
    }
}

namespace Đề_12_bài_2
{
    public partial class Form1 : Form
    {
        int[] A = new int[100];
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i = 0 ;
            if (textBox1.Text != "")
                try
                {
                    A[i] = int.Parse(textBox1.Text);
                    listBox1.Items.Add(textBox1.Text);
                    i++;
                }
                catch
                {
                    MessageBox.Show("Số nhập vào không đúng");
                }
            textBox1.Clear();
            textBox1.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            foreach (string item in listBox1.Items)
            {
                int n = int.Parse(item);
                bool kt = true;
                for (int i = 2; i < n / 2 + 1; i++)
                    if (n % i == 0)
                    {
                        kt = false;
                        break;
                    }
                if (kt) listBox2.Items.Add(item);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            int n = listBox1.Items.Count;
            int[] A = new int[n];
            int i = 0;
            foreach (string item in listBox1.Items)
            {
                A[i] = int.Parse(item);
                i++;
            }
            Array.Sort(A);
            for (i = 0; i < n; i++)
                listBox2.Items.Add(A[i].ToString());
        }
    }
}

Đề 16.
       
namespace Đề_16_bài_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            Console.Write("Nhap n: ");
            bool kt = int.TryParse(Console.ReadLine(), out n);
            while (!kt)
            {
                Console.Write("Nhap lai n: ");
                kt = int.TryParse(Console.ReadLine(), out n);
            }
            int[] A = new int[n];
            for (int i = 0; i < n; i++)
            {
                Console.Write("Nhap A[{0}]: ");
                A[i] = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("Day so nguyen da nhap la:");
            for (int i = 0; i < n; i++)
                Console.Write("   {0}", A[i]);
            Console.WriteLine();
            Array.Sort(A);
            Console.WriteLine("Day sau khi da sap xep la:");
            for (int i = 0; i < n; i++)
                Console.Write("   {0}", A[i]);
            Console.WriteLine();
            Console.Write("Nhap x: ");
            int x = int.Parse(Console.ReadLine());
            kt = false;
            for (int i = 0; i < n; i++)
                if (A[i] == x)
                {
                    kt = true;
                    break;
                }
            if (kt) Console.WriteLine("Trong mang co phan tu bang {0}", x);
            else Console.WriteLine("Trong mang khong co phan tu nao bang {0}", x);
            Console.WriteLine("Phan tu lon nhat trong mang la: {0}",A.Max());
            Console.ReadLine();
        }
    }
}

namespace Đề_16_bài_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
            int n;
            bool kt = int.TryParse(textBox1.Text, out n);
            if (!kt) MessageBox.Show("Dữ liệu nhập vào không đúng");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int n = int.Parse(textBox1.Text);
            richTextBox1.Clear();
            richTextBox1.Visible = true;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j <= i; j++) richTextBox1.Text += "*  ";
                richTextBox1.Text += Environment.NewLine;
            }
            richTextBox2.Clear();
            richTextBox2.Visible = true;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j <= n - i - 1; j++) richTextBox2.Text += "*  ";
                richTextBox2.Text += Environment.NewLine;
            }
            richTextBox3.Clear();
            richTextBox3.Visible = true;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n - i -1; j++) richTextBox3.Text += "   ";
                for (int j = n - i - 1; j < n; j++) richTextBox3.Text += "*  ";
                richTextBox3.Text += Environment.NewLine;
            }
            richTextBox4.Clear();
            richTextBox4.Visible = true;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0;j<i;j++) richTextBox4.Text += "   ";
                for (int j =i; j<n; j++) richTextBox4.Text += "*  ";
                richTextBox4.Text += Environment.NewLine;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có chắc chắn muốn thoát không","Thông báo",MessageBoxButtons.YesNo)) this.Close();
        }
    }
}

Đề 17.
namespace Đề_17_bài_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int m = 0, n = 0;
            bool kt = false;
            while (!kt)
            {
                Console.Write("Nhap so hang cua ma tran: ");
                kt = int.TryParse(Console.ReadLine(), out n);
            }
            kt = false;
            while (!kt)
            {
                Console.Write("Nhap so cot cua ma tran: ");
                kt = int.TryParse(Console.ReadLine(), out m);
            }
            int[,] A = new int[n, m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                {
                    Console.Write("Hay nhap A[{0},{1}]:", i, j);
                    A[i, j] = int.Parse(Console.ReadLine());
                }
            Console.WriteLine("Ma tran vua nhap la:");
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++) Console.Write("{0}  ", A[i, j]);
                Console.WriteLine();
            }
            for (int i = 0; i < n; i++)
            {
                int max = A[i, 0];
                for (int j = 1; j < m; j++) if (max < A[i, j]) max = A[i, j];
                Console.WriteLine("Phan tu lon nhat cua hang {0} la: {1}", i, max);

            }
            int dem = 0;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    if (A[i, j] % 2 == 0 && A[i, j] > 0) dem++;
            Console.WriteLine("So phan tu duong chan co trong ma tran la: {0}", dem);
            int tong = 0;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++) tong += A[i, j];
            Console.WriteLine("Tong cac phan tu trong ma tran la: {0}", tong);
            Console.ReadLine();
        }
    }
}
namespace Đề_17_bài_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
            button2.Enabled = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            float a,b;
            bool kt1 = float.TryParse(textBox1.Text, out a);
            bool kt2 = float.TryParse(textBox2.Text, out b);
            if (kt2 && kt1)
            {
                MessageBox.Show("Dữ liệu hợp lệ");
                button2.Enabled = true;
            }
            else
            {
                if (!kt1) textBox1.Focus();
                if (!kt1) textBox2.Focus();
                MessageBox.Show("Dữ liệu nhập vào không đúng");
            }
           
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            button2.Enabled = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label4.Visible = true;
            int a = int.Parse(textBox1.Text);
            int b = int.Parse(textBox2.Text);
            if (a == 0) if (b <= 0) label4.Text = "Kết quả: Bất phương trình vô nghiệm";
                else label4.Text = "Kết quả: Bất phương trình đúng với mọi x";
            else if (a > 0) label4.Text = "Kết quả: Bất phương trình có nghiệm x > " + (-b / a).ToString();
            else label4.Text = "Kết quả: Bất phương trình có nghiệm x < " + (-b / a).ToString();
        }
    }
}

Đề 18.
namespace Đề_18_bài_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int n = int.Parse(textBox1.Text);
            int q = 2;
            int i = 0;
            label3.Text = "Số nguyên " + n.ToString() + " Chuyển sang hệ nhị phân là: ";
            chuyendoi(ref n, q, ref i);
        }

        private void chuyendoi(ref int n, int q, ref int i)
        {
            string[] A = new string[100];
            int du = n % q;
            while (n != 0)
            {
                switch (du)
                {
                    case 10: A[i] = "A"; break;
                    case 11: A[i] = "B"; break;
                    case 12: A[i] = "C"; break;
                    case 13: A[i] = "D"; break;
                    case 14: A[i] = "E"; break;
                    case 15: A[i] = "F"; break;
                    default: A[i] = du.ToString(); break;
                }
                i++;
                n = n / q;
                du = n % q;
            }
            for (int j = i; j >= 0; j--) label3.Text += A[j];
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
            try
            {
                int n = int.Parse(textBox1.Text);
            }
            catch
            {
                MessageBox.Show("Dữ liệu nhập vào không đúng");
                this.Focus();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int n = int.Parse(textBox1.Text);
            int q = 16;
            int i = 0;
            label3.Text = "Số nguyên " + n.ToString() + " Chuyển sang hệ Hexa là: ";
            chuyendoi(ref n, q, ref i);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có thực sự muốn thoát không","Thông báo",MessageBoxButtons.YesNo)) this.Close();
        }
    }
}

namespace Đề_18_bài_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            int n = int.Parse(textBox1.Text);
            int m = int.Parse(textBox2.Text);
            int sodu = n % m;
            int a = n;
            int b = m;
            while (sodu != 0)
            {
                a = b;
                b = sodu;
                sodu = a % b;
            }
            if (e.NewValue == CheckState.Checked)
            {
                richTextBox1.Clear();
                if (checkedListBox1.GetItemChecked(0) == true || checkedListBox1.SelectedIndex == 0) richTextBox1.Text += "UCLN = " + b.ToString() + Environment.NewLine;
                if (checkedListBox1.GetItemChecked(1) == true || checkedListBox1.SelectedIndex == 1) richTextBox1.Text += "Số lớn nhất = " + Math.Max(m, n).ToString() + Environment.NewLine;
            }
            else
            {
                richTextBox1.Clear();
                if (checkedListBox1.GetItemChecked(0) == true && checkedListBox1.SelectedIndex != 0) richTextBox1.Text += "UCLN = " + b.ToString() + Environment.NewLine;
                if (checkedListBox1.GetItemChecked(1) == true && checkedListBox1.SelectedIndex != 1) richTextBox1.Text += "Số lớn nhất = " + Math.Max(m, n).ToString() + Environment.NewLine;
            }

        }

      
    }
}

Đề 20.
namespace Đề_20_bài_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
            try
            {
                int n = int.Parse(textBox1.Text);
            }
            catch
            {
                MessageBox.Show("Dữ liệu nhập vào không đúng");
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            try
            {
                int m = int.Parse(textBox2.Text);
            }
            catch
            {
                MessageBox.Show("Dữ liệu nhập vào không đúng");
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int n = int.Parse(textBox1.Text);
            int m = int.Parse(textBox2.Text);
            if (comboBox1.SelectedIndex == 0)
            {
                int b = timuoc(n, m);
                label4.Text = "Ước số chung lớn nhất là: " + b.ToString();
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                int b = m * n / timuoc(m, n);
                label4.Text = "Bội số chung nhỏ nhất là: " + b.ToString();
            }
            else label4.Text = "Số lớn nhất là: " + Math.Max(m, n);
        }

        private static int timuoc(int n, int m)
        {
            int a = n;
            int b = m;
            int c = a % b;
            while (c != 0)
            {
                a = b;
                b = c;
                c = a % b;
            }
            return b;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có chắc chắn muốn thoát không","Thông báo",MessageBoxButtons.YesNo)) this.Close();
        }
    }
}

namespace Đề_20_bài_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int n = int.Parse(textBox1.Text);
            int m = int.Parse(textBox2.Text);
            if (comboBox1.SelectedIndex == 0) label6.Text = (m + n).ToString();
            else if (comboBox1.SelectedIndex == 1) label6.Text = (n - m).ToString();
            else if (comboBox1.SelectedIndex == 2) label6.Text = (m * n).ToString();
            else if (comboBox1.SelectedIndex == 3) label6.Text = ((float)n / m).ToString();
            else if (comboBox1.SelectedIndex == 4) label6.Text = (Math.Pow(n, m)).ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có chắc chắn muốn thoát không?", "Thông báo", MessageBoxButtons.YesNo)) this.Close();
        }
    }
}




0 comments:

Post a Comment