laptrinh2














câu 12:
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;
using Microsoft.VisualBasic;

namespace Bai12_Matran
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int[,] A, B;
  
        private int[,] NhapMatran(int n)
        {
            int[,] A = new int[n, n];
            for (int i = 0; i < n; i++)
               for (int j = 0; j < n; j++)
                {
                    string tg = Interaction.InputBox("A[" + i.ToString() + j.ToString() + "]", "Nhập phần tử");
                    A[i, j] = int.Parse(tg);
                  
                }
           
            return A;
        }
      

 private void HienMatran(int[,] A, int n, RichTextBox rtb)
        {
            rtb.Text = "";
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    rtb.Text += A[i, j].ToString()+"    ";
                }
                rtb.Text += "\n";
            }
          
        }
 private void btNhapA_Click(object sender, EventArgs e)
        {
            int n = int.Parse(txtKichthuoc.Text);
            A = NhapMatran(n);
            HienMatran(A, n, rtb_MatranA);
        
        }

     private void btNhapB_Click(object sender, EventArgs e)
        {
           //B = Nhapmt(rtb_MatranB);
            int n = int.Parse(txtKichthuoc.Text);
            B = NhapMatran(n);
            HienMatran(B,n, rtb_MatranB);
            //rtb_MatranB.Text= HienMatran(B, n);
        }
        private int[,] Tinhtich(int[,] A, int[,] B, int n)
        {
            int[,] C = new int[n, n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                     C[i,j] = 0;
                    for (int k = 0; k < n; k++)
                    {
                        C[i,j] += A[i, k] * A[k, j];

                    }
                  
                }
              
            }
            return C;
        }

     private void bt_Tich_Click(object sender, EventArgs e)
        {
            int n = int.Parse(txtKichthuoc.Text);
            HienMatran(Tinhtich(A,B,n),n, rtb_MatranTich);
        }
=======================================================
câu 16

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 Bài_16_radiobuttun
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

private void txtNhap_TextChanged(object sender, EventArgs e)
        {
            if (txtNhap.Text != "")
            {
                try
                {
                    int n = int.Parse(txtNhap.Text);
                }
                catch
                {
                    MessageBox.Show("Hãy nhập số nguyên");
                    txtNhap.Clear();
                    txtNhap.Focus();
                }
            }
        }
private bool KTNT(int n)
        {
            bool kt = true;

            for (int i = 2; i <= n / 2; i++)
            {
                if (n % i == 0) { kt = false; break; }
            }

            return kt;
        }
private bool KTCP(int n)
        {
  return ((double)n ==Math.Pow(Math.Floor(Math.Sqrt(n)),2));
        }
private int TinhTong(int n)
        {
            int t = 0;
            while (n > 0)
            {
                t += n % 10;
                n = n / 10;
            }
            return t;
        }

private void rdbKTNT_Click(object sender, EventArgs e)
        {
            int n = int.Parse(txtNhap.Text);
            if (KTNT(n) == true) lbKQ.Text = "Kết quả: " + n.ToString() + " là số nguyên tố";
            else
            lbKQ.Text = "Kết quả: " + n.ToString() + " không phải là số nguyên tố";
        }

private void rdbKTCP_CheckedChanged(object sender, EventArgs e)
        {
            int n = int.Parse(txtNhap.Text);
            if (KTCP(n) == true) lbKQ.Text = "Kết quả: " + n.ToString() + " là số chính phương";
            else
                lbKQ.Text = "Kết quả: " + n.ToString() + " không phải là số chính phương";
        }

private void rdbTinhtong_Click(object sender, EventArgs e)
        {
            int n = int.Parse(txtNhap.Text);
            lbKQ.Text = "Kết quả: Tổng các chữ số của " + n.ToString() + " là " + TinhTong(n).ToString();
        }
    }

}
==============================================

câu 23

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 Bài_23_Chọn_kiểu_chữ
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
private void rdRed_CheckedChanged(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Red;
        }

private void btXoa_Click(object sender, EventArgs e)
        {
          
            rtbChuoi.Clear();
            rtbChuoi.Focus();
        }

   private void btThoat_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();
        }

private void chkDam_CheckedChanged(object sender, EventArgs e)
        {
            rtbChuoi.Font = new Font(rtbChuoi.Font.Name,
                                        rtbChuoi.Font.Size,
                                        rtbChuoi.Font.Style^FontStyle.Bold);
        }
private void chkNghieng_CheckedChanged(object sender, EventArgs e)
        {
            rtbChuoi.Font = new Font(rtbChuoi.Font.Name,
                                        rtbChuoi.Font.Size,
                                        rtbChuoi.Font.Style ^ FontStyle.Italic);
        }

private void chkGachchan_CheckedChanged(object sender, EventArgs e)
        {
            rtbChuoi.Font = new Font(rtbChuoi.Font.Name,
                                        rtbChuoi.Font.Size,
                                        rtbChuoi.Font.Style ^FontStyle.Underline);
        }

private void rdbDo_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Red;
        }

private void rdbDen_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Black;
        }

private void rdbXanhla_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Green;
        }

private void rdbVang_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Yellow;
        }

private void rdbXanhduong_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Blue;
        }

private void rdbTim_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Magenta;
        }
                   
    }
}
================================================
câu 24
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 Bài_23_Chọn_kiểu_chữ
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
private void rdRed_CheckedChanged(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Red;
        }

private void btXoa_Click(object sender, EventArgs e)
        {
          
            rtbChuoi.Clear();
            rtbChuoi.Focus();
        }

   private void btThoat_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();
        }

private void chkDam_CheckedChanged(object sender, EventArgs e)
        {
            rtbChuoi.Font = new Font(rtbChuoi.Font.Name,
                                        rtbChuoi.Font.Size,
                                        rtbChuoi.Font.Style^FontStyle.Bold);
        }
private void chkNghieng_CheckedChanged(object sender, EventArgs e)
        {
            rtbChuoi.Font = new Font(rtbChuoi.Font.Name,
                                        rtbChuoi.Font.Size,
                                        rtbChuoi.Font.Style ^ FontStyle.Italic);
        }

private void chkGachchan_CheckedChanged(object sender, EventArgs e)
        {
            rtbChuoi.Font = new Font(rtbChuoi.Font.Name,
                                        rtbChuoi.Font.Size,
                                        rtbChuoi.Font.Style ^FontStyle.Underline);
        }

private void rdbDo_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Red;
        }

private void rdbDen_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Black;
        }

private void rdbXanhla_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Green;
        }

private void rdbVang_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Yellow;
        }

private void rdbXanhduong_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Blue;
        }

private void rdbTim_Click(object sender, EventArgs e)
        {
            rtbChuoi.ForeColor = Color.Magenta;
        }
                   
    }
}
===================================================
câu 27
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 ComboBox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            ComboBox_Load();
        }

        private void ComboBox_Load()
        {
            // Đưa các font chữ vào ComboBox Font
FontFamily[] ff = FontFamily.Families;
            for (int i = 0; i < ff.Length; i++)
            {
                cbFont.Items.Add(ff[i].Name);
            }
// Đưa các cỡ chữ vào ComboBox Size
            for (int i = 8; i <= 72; i++)
            {
                cbSize.Items.Add(i);
              
            }
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            rtbString.Font =  new Font(cbFont.Text, rtbString.Font.Size);
        }

        private void cbSize_SelectedIndexChanged(object sender, EventArgs e)
        {
           rtbString.Font= new Font(rtbString.Font.Name, float.Parse(cbSize.Text));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            rtbString.Clear();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

       
    }
}
===================================================
câu 30 
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 Bài_30_string
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

private string chuanhoa(string s)
        {
            s = s.Trim();
            int i = 0;
            while (i < s.Length)
            {
                if ((s[i] == ' ') && (s[i + 1] == ' '))
                    s = s.Remove(i, 1);
                else i++;
               
            }
            return s;
        }
private void btchuanhoa_Click(object sender, EventArgs e)
        {
            rtbKQ.Text = chuanhoa(rtbNhap.Text);
        }

private void btDem_Click(object sender, EventArgs e)
        {
            string s = chuanhoa(rtbNhap.Text);
            int d = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == ' ') d++;
            }
            rtbKQ.Text =  "Số từ trong xâu là: " +(d+1).ToString();
        }
    }
}

0 comments:

Post a Comment