By GokiSoft.com| 09:51 01/11/2021|
C Sharp

1000 Bài tập lập trình C# - Lập trình C# - Lập Trình C Sharp

Bài 1.

            Viết chương trình java tạo và thực thi theo menu sau:

1.      Nhập vào tên của bạn

2.      Hiển thị tên vừa nhập.

3.      Thoát.

 

Bài 2. Viết chương trình java thực thi theo menu sau:

1.      Nhập vào 2 số nguyên

2.      Hiển thị 2 số vừa nhập

3.      Tổng 2 số

4.      Tích 2 số

5.      Hiệu 2 số

6.      Thương 2 số.

7.      Thoát.

 

Bài 3. Viết chương trình java thực thi theo menu sau:

1.      Nhập vào họ tên của bạn

2.      Nhập vào điểm toán lý hóa.

3.      Tính tổng 3 môn

4.      Tính trung bình 3 môn.

5.      Thoát.

 

Bài 4.

            Viết chương trình java cho phép tạo và thực thi theo menu sau:

1.      Nhập vào một số nguyên dương n.

2.      Tính tổng các số từ 1 đến n

3.      Kiểm tra n có là số nguyên tố

4.      Kiểm tra n có là số hoàn hảo.

5.      In ra các số nguyên tố từ 1 đến n

6.      In ra các số hoàn hảo từ 1 đến n.

7.      Hiển thị số n thành tích các thừa số nguyên tố.

8.      Thoát

(Hiển thị 1 số nguyên dương thành tích các thừa số nguyên tố: n = 24 thì in ra: n = 2^3*3)

 

Bài 5.

            Viết chương trình java tạo và thực thi theo menu sau:

1.      Nhập vào số nguyên dương n

2.      Tính tổng: 1 + 1/2 + 1/3 + ... + 1/n

3.      Tính tổng: 1 + 1/2! + 1/3! + ... + 1/n!

4.      Thoát.

 

Bài 6.

            Viết chương trình java tạo và thực thi theo menu sau:

1.      Nhập vào số nguyên dương n, số nguyên x bất kỳ

2.      Tính tổng: 1 + x + x^2/2! + x^3/3! + ... + x^n / n!

3.      Tính tổng: 1 +x – x^2/2! + x^3/3! + ... + (-1)^n-1 * x^n / n!

4.      Thoát.

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Trương Công Vinh [T1907A]
Trương Công Vinh

2020-05-27 07:21:56



using System;
using System.Collections.Generic;
using System.Text;

namespace Csharp1000Bt
{
    class bt4
    {
        int n { get; set; }
        public bt4()
        {

        }
        public void baitap4()
        {
            int chosse;
            do
            {
                showMenu();
                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        input();
                        break;
                    case 2:
                        Console.WriteLine("Tong cac so tu 1 -> n la: {0}", tong(n));
                        break;
                    case 3:
                        if (checkSNT(n))
                        {
                            Console.WriteLine("{0} la 1 so nguyen to!!", n);
                        }
                        else
                        {
                            Console.WriteLine("{0} khong phai la 1 so nguyen to!!", n);
                        }
                        break;
                    case 4:
                        if (checkSHH(n))
                        {
                            Console.WriteLine("{0} la 1 so hoan hao!!", n);
                        }
                        else
                        {
                            Console.WriteLine("{0} khong phai la 1 so hoan hao!!", n);
                        }
                        break;
                    case 5:
                        inputNguyenTo(n);

                        break;
                    case 6:
                        inputHoanHao(n);

                        break;
                    case 7:
                        PhanTich(n);
                        break;
                    case 8:
                        Console.Write("Thoat!!!!");
                        break;
                    default:
                        Console.Write("Nhap sai!!! Moi nhap lai......");
                        break;
                }
            } while (chosse != 7);
        }


        void showMenu()
        {
            Console.WriteLine("\t\t\t MeNU");
            Console.WriteLine("1.      Nhập vào một số nguyên dương n.");
            Console.WriteLine("2.      Tính tổng các số từ 1 đến n");
            Console.WriteLine("3.      Kiểm tra n có là số nguyên tố");
            Console.WriteLine("4.      Kiểm tra n có là số hoàn hảo.");
            Console.WriteLine("5.      In ra các số nguyên tố từ 1 đến n");
            Console.WriteLine("6.      In ra các số hoàn hảo từ 1 đến n.");
            Console.WriteLine("7.      Hiển thị số n thành tích các thừa số nguyên tố.");
            Console.WriteLine("8.      Thoát.");
            Console.Write("Chon: ");
        }

        private void input()
        {
            for (; ; )
            {
                Console.Write("Nhap so n: ");
                n = int.Parse(Console.ReadLine());
                if (n > 0)
                    break;
                Console.WriteLine("Nhap sai!!!! Moi nhap lai");
            }
        }

        private int tong(int n)
        {
            

            if (n==1)
            {
                return 1;
            }
            else
            {
               return tong(n - 1)+n;
            }

            
        }
        private bool checkSNT(int n)
        {
            if (n <= 1)
            {
                return false;
            }
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

        private bool checkSHH(int n)
        {
            int sum = 0;
            for (int i = 1; i <= n / 2; i++)
            {
                if (n % i == 0)
                    sum += i;
            }
            if (sum == n) return true;
            return false;
        }

        private void inputNguyenTo(int n)
        {
            Console.Write("Cac so nguyen to tu 1 -> n la :");
            for (int i = 1; i < n; i++)
            {
                if (checkSNT(i))
                {
                    Console.Write("{0}, ", i);
                }
            }
        }

        private void inputHoanHao(int n)
        {
            Console.Write("Cac so hoan hao tu 1 -> n la :");
            for (int i = 1; i < n; i++)
            {
                if (checkSHH(i))
                {
                    Console.Write("{0}, ", i);
                }
            }
        }

        private void PhanTich(int n)
        {
            Console.Write("{0} = ", n);
            for (int i = 2; i <= n; i++)
            {
                for (int j = i; ;)
                {
                    if (n % j == 0 && checkSNT(j))
                    {
                        Console.Write("{0} * ", j);
                        n /= j;
                    }
                    else
                        break;
                }
            }
        }
    }
}



using System;
using System.Collections.Generic;
using System.Text;

namespace Csharp1000Bt
{
    class bt6
    {

        int n { get; set; }
        int x { get; set; }

        public bt6()
        {

        }
        public void baitap6()
        {
            int chosse;
            do
            {
                showMenu();

                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        input();
                        break;
                    case 2:

                        Console.WriteLine("  1 + x + x^2/2! + x^3/3! + ... + x^n / n! = {0}", sum2(n,x));
                        break;
                    case 3:
                        Console.WriteLine("    1 +x – x^2/2! + x^3/3! + ... + (-1)^n-1 * x^n / n!={0}", sum3(n));
                        break;
                    case 4:
                        Console.WriteLine("Thoat!!!!");
                        break;
                    default:
                        Console.WriteLine("Nhap sai moi nhap lai!!!");
                        break;
                }
            } while (chosse != 4);
        }
        void showMenu()
        {
            Console.WriteLine("\t\t\t MeNU");
            Console.WriteLine("1.      Nhập vào một số nguyên dương n.");
            Console.WriteLine("2.      Tính tổng: 1 + x + x^2/2! + x^3/3! + ... + x^n / n!");
            Console.WriteLine("3.      Tính tổng: 1 +x – x^2/2! + x^3/3! + ... + (-1)^n-1 * x^n / n!");
            Console.WriteLine("4.      Thoát.");
            Console.Write("Chon: ");
        }
        private void input()
        {
            for (; ; )
            {
                Console.Write("Nhap so n>0: ");
                this.n = int.Parse(Console.ReadLine());
                Console.Write("Nhap so x: ");
                this.x = int.Parse(Console.ReadLine());
                if (n > 0 )
                    break;
                Console.WriteLine("Nhap sai(n>0)!!!! Moi nhap lai");
            }
        }
        private float sum2(int n,int x)
        {
            if (n == 0)
            {
                return 1;
            }
            else
            {
                return (float)((Math.Pow(x,n)/giaithua(n))) + sum2(n - 1,x);
            }
        }
        private float sum3(int n)
        {

            if (n == 0)
            {
                return 1;
            }
            else
            {
                return  (float)(Math.Pow(-1,(n-1))* (Math.Pow(x, n) / giaithua(n))) +sum3(n - 1);
            }
        }
        private int giaithua(int n)
        {
            if (n == 1)
            {
                return 1;
            }
            else
            {
                return n * giaithua(n - 1);
            }
        }


        

    }
}



using System;
using System.Collections.Generic;
using System.Text;

namespace Csharp1000Bt
{
    class bt5
    {
        int n { get; set; }

        public bt5()
        {

        }
        public void baitap5()
        {
            int chosse;
            do
            {
                showMenu();

                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        input();
                        break;
                    case 2:
                        
                        Console.WriteLine("  tổng 1 + 1/2 + 1/3 + ... + 1/{0} = {1}", n, sum2(n));
                        break;
                    case 3:
                        Console.WriteLine("   tổng: 1 + 1/2! + 1/3! + ... + 1/{0}! = {1}", n,sum3(n));
                        break;
                    case 4:
                        Console.WriteLine("Thoat!!!!");
                        break;
                    default:
                        Console.WriteLine("Nhap sai moi nhap lai!!!");
                        break;
                }
            } while (chosse != 4);
        }
        void showMenu()
        {
            Console.WriteLine("\t\t\t MeNU");
            Console.WriteLine("1.      Nhập vào một số nguyên dương n.");
            Console.WriteLine("2.      Tính tổng: 1 + 1/2 + 1/3 + ... + 1/n");
            Console.WriteLine("3.      Tính tổng: 1 + 1/2! + 1/3! + ... + 1/n!");         
            Console.WriteLine("4.      Thoát.");
            Console.Write("Chon: ");
        }
        private void input()
        {
            for (; ; )
            {
                Console.Write("Nhap so n: ");
                this.n = int.Parse(Console.ReadLine());
                if (n > 0)
                    break;
                Console.WriteLine("Nhap sai!!!! Moi nhap lai");
            }
        }
        private float sum2(int n)
        {
            if ( n==1 )
            {
                return 1;
            }
            else
            {
                return (1.0F / n) +sum2(n-1) ;
            }
        }
        private float sum3(int n)
        {

            if (giaithua(n) == 1)
            {
                return 1;
            }
            else
            {
                return (1.0f/ giaithua(n))+sum3(n - 1);
            }
        }
        private int giaithua(int n)
        {
            if (n == 1)
            {
                return 1;
            }
            else
            {
                return n* giaithua(n - 1) ;
            }
        }
    }
}



using System;
using System.Collections.Generic;
using System.Text;

namespace Csharp1000Bt
{
    class bt3
    {
        private float a { get; set; }
        private float b { get; set; }
        private float c { get; set; }
        private string name { get; set; }


        public bt3()
        {

        }

        public void baitap3()
        {
            int chosse;
            do
            {
                showMenu();
                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        inputTen();
                        break;
                    case 2:
                        inputDiem();
                        break;
                    case 3:
                        Console.Write("Tong diem 3 mon la: {0}", tong());

                        break;
                    case 4:
                        Console.Write("TBC 3 mon la: {0}", TBC());

                        break;
                    case 5:
                        Console.Write("Thoat!!!!");
                        break;
                    default:
                        Console.Write("Nhap sai!!! Moi nhap lai......");
                        break;
                }
            } while (chosse != 5);
        }
        private void showMenu()
        {
            Console.WriteLine("          MeNU");
            Console.WriteLine("1.      Nhập vào họ tên của bạn");
            Console.WriteLine("2.      Nhập vào điểm toán lý hóa.");
            Console.WriteLine("3.      Tính tổng 3 môn");
            Console.WriteLine("4.      Tính trung bình 3 môn.");
            Console.WriteLine("5.      Thoát.");
            Console.Write("Chon: ");
        }

        private void inputTen()
        {
            Console.Write("Nhap ten: ");
            name = Console.ReadLine();

        }
        private void inputDiem()
        {
            Console.Write("Nhap diem Toan: ");
            a = float.Parse(Console.ReadLine());
            Console.Write("Nhap diem Ly: ");
            b = float.Parse(Console.ReadLine());
            Console.Write("Nhap diem Hoa: ");
            c = float.Parse(Console.ReadLine());
        }

        private float tong()
        {
            return (float)a + b + c;
        }
        private float TBC()
        {
            return (float)(a + b + c) / 3;
        }
    }
}



using System;
using System.Collections.Generic;
using System.Text;

namespace Csharp1000Bt
{
    class bt2
    {
          float a { get; set; }
          float b { get; set; }

        public bt2()
        {

        }
        public void baitap2()
        {
            int chosse;
            do
            {
                showMenu();
                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        input();
                        break;
                    case 2:
                        display();
                        break;
                    case 3:
                        Console.Write("Tong 2 so vua nhap la: {0}", tong());

                        break;
                    case 4:
                        Console.Write("Tich 2 so vua nhap la: {0}", tich());

                        break;
                    case 5:
                        Console.Write("Thuong 2 so vua nhap la: {0}", thuong());

                        break;
                    case 6:
                        Console.Write("Hieu 2 so vua nhap la: {0}", hieu());

                        break;
                    case 7:
                        Console.Write("Thoat!!!!");
                        break;
                    default:
                        Console.Write("Nhap sai!!! Moi nhap lai......");
                        break;
                }
            } while (chosse != 7);

        }
        private  void input()
        {
            Console.Write("Nhap so thu 1: ");
            a = float.Parse(Console.ReadLine());
            Console.Write("Nhap so thu 2: ");
            b = float.Parse(Console.ReadLine());
        }

        private  void display()
        {
            Console.WriteLine("Hai so vua nhap la: {0} va {1}", a, b);
        }

        private  float tong()
        {
            return (float)a + b;
        }
        private  float tich()
        {
            return (float)a * b;
        }
        private  float thuong()
        {
            return (float)a / b;
        }
        private  float hieu()
        {
            return (float)a - b;
        }
        private  void showMenu()
        {
            Console.WriteLine("\t\t\t MeNU");
            Console.WriteLine("1.      Nhập vào 2 số nguyên");
            Console.WriteLine("2.      Hiển thị 2 số vừa nhập");
            Console.WriteLine("3.      Tổng 2 số");
            Console.WriteLine("4.      Tích 2 số");
            Console.WriteLine("5.      Hiệu 2 số");
            Console.WriteLine("6.      Thương 2 số.");
            Console.WriteLine("7.      Thoát.");
            Console.Write("Chon: ");
        }
    }
}



using System;
using System.Collections.Generic;
using System.Text;

namespace Csharp1000Bt
{
    class bt1
    {
         string fullkname { get; set; }

        public bt1()
        {

        }
        public void baitap1()
        {
            int chosse;
            do
            {
                showMenu();

                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        Console.Write("Nhap ten: ");
                        fullkname = Console.ReadLine();
                        break;
                    case 2:
                        Console.WriteLine("Ten: {0}", fullkname);
                        break;
                    case 3:
                        Console.WriteLine("Thoat!!!!");
                        break;
                    default:
                        Console.WriteLine("Nhap sai moi nhap lai!!!");
                        break;
                }
            } while (chosse != 3);
        }
        private void showMenu()
        {
            Console.WriteLine("     MENU");
            Console.WriteLine("1.      Nhập vào tên của bạn");
            Console.WriteLine("2.      Hiển thị tên vừa nhập.");
            Console.WriteLine("3.      Thoát.");
            Console.Write("Chon: ");
        }
    }
}



using System;
using System.Text;
namespace Csharp1000Bt
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            int c;
            do
            {
                menu();
                c = int.Parse(Console.ReadLine());
                switch (c)
                {
                    case 1:
                        bt1 bt1 = new bt1();
                        bt1.baitap1();
                        break;

                    case 2:
                        bt2 bt2 = new bt2();
                        bt2.baitap2();
                        break;
                    case 3:
                        bt3 bt3 = new bt3();
                        break;
                    case 4:
                        bt4 bt4 = new bt4();
                        bt4.baitap4();
                        break;
                    case 5:
                        bt5 bt5 = new bt5();
                        bt5.baitap5();
                        break;
                    case 6:
                        bt6 bt6 = new bt6();
                        bt6.baitap6();
                        break;
                    case 7:

                        break;
                    default:

                        break;

                }

            } while (c!=7);



        }
        static void menu()
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("1.check bt1");
            Console.WriteLine("2.Check bt2");
            Console.WriteLine("3.check bt3");
            Console.WriteLine("4.check bt4");
            Console.WriteLine("5. Check bt5!");
            Console.WriteLine("6. Check bt6!");
            Console.WriteLine("7.Exit !");
            Console.WriteLine(" Choose : ");


        }
    }
}



Lê Minh Bắc [T1907A]
Lê Minh Bắc

2020-05-25 08:25:48

Bai1:

using System;

namespace Lession6
{
    class Bai1
    {
        public static string name { get; set; }
        static void Main(string[] args)
        {
            int chosse;
            do
            {
                showMenu();
                
                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        Console.Write("Nhap ten: ");
                        name = Console.ReadLine();
                        break;
                    case 2:
                        Console.WriteLine("Ten: {0}",name);
                        break;
                    case 3:
                        Console.WriteLine("Thoat!!!!");
                        break;
                    default:
                        Console.WriteLine("Nhap sai moi nhap lai!!!");
                        break;
                }
            } while (chosse != 3);

            Console.ReadKey();

        }

        static void showMenu()
        {
            Console.WriteLine("\t\t\tMENU");
            Console.WriteLine("1.      Nhập vào tên của bạn");
            Console.WriteLine("2.      Hiển thị tên vừa nhập.");
            Console.WriteLine("3.      Thoát.");
            Console.Write("Chon: ");
        }
    }

}

Bai2:
using System;

namespace Lession6
{
    class Bai2
    {
        public static float a { get; set; }
        public static float b { get; set; }
        public static void Main(String[] agrs)
        {
            int chosse;
            do
            {
                showMenu();
                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        input();
                        break;
                    case 2:
                        display();
                        break;
                    case 3:
                        Console.Write("Tong 2 so vua nhap la: {0}", tong());
                        
                        break;
                    case 4:
                        Console.Write("Tich 2 so vua nhap la: {0}", tich());
                        
                        break;
                    case 5:
                        Console.Write("Thuong 2 so vua nhap la: {0}", thuong());
                        
                        break;
                    case 6:
                        Console.Write("Hieu 2 so vua nhap la: {0}", hieu());
                        
                        break;
                    case 7:
                        Console.Write("Thoat!!!!");
                        break;
                    default:
                        Console.Write("Nhap sai!!! Moi nhap lai......");
                        break;
                }
            } while (chosse != 7);

            Console.ReadKey();
        }

        public static void showMenu()
        {
            Console.WriteLine("\t\t\t MeNU");
            Console.WriteLine("1.      Nhập vào 2 số nguyên");
            Console.WriteLine("2.      Hiển thị 2 số vừa nhập");
            Console.WriteLine("3.      Tổng 2 số");
            Console.WriteLine("4.      Tích 2 số");
            Console.WriteLine("5.      Hiệu 2 số");
            Console.WriteLine("6.      Thương 2 số.");
            Console.WriteLine("7.      Thoát.");
            Console.Write("Chon: ");
        }

        public static void input()
        {
            Console.Write("Nhap so thu 1: ");
            a = float.Parse(Console.ReadLine());
            Console.Write("Nhap so thu 2: ");
            b = float.Parse(Console.ReadLine());
        }

        public static void display()
        {
            Console.WriteLine("Hai so vua nhap la: {0} va {1}", a, b);
        }

        public static float tong()
        {
            return (float)a + b;
        }
        public static float tich()
        {
            return (float)a * b;
        }
        public static float thuong()
        {
            return (float)a/b;
        }
        public static float hieu()
        {
            return (float) a - b;
        }

    }
}

Bai3:
using System;

namespace Lession6
{
    class Bai3
    {
        public static float a { get; set; }
        public static float b { get; set; }
        public static float c { get; set; }
        public static string name { get; set; }

        public static void Main(String[] agrs)
        {
            int chosse;
            do
            {
                showMenu();
                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        inputTen();
                        break;
                    case 2:
                        inputDiem();
                        break;
                    case 3:
                        Console.Write("Tong diem 3 mon la: {0}", tong());

                        break;
                    case 4:
                        Console.Write("TBC 3 mon la: {0}", TBC());

                        break;
                    case 5:
                        Console.Write("Thoat!!!!");
                        break;
                    default:
                        Console.Write("Nhap sai!!! Moi nhap lai......");
                        break;
                }
            } while (chosse != 5);

            Console.ReadKey();
        }

        public static void showMenu()
        {
            Console.WriteLine("\t\t\t MeNU");
            Console.WriteLine("1.      Nhập vào họ tên của bạn");
            Console.WriteLine("2.      Nhập vào điểm toán lý hóa.");
            Console.WriteLine("3.      Tính tổng 3 môn");
            Console.WriteLine("4.      Tính trung bình 3 môn.");
            Console.WriteLine("5.      Thoát.");
            Console.Write("Chon: ");
        }

        public static void inputTen()
        {
            Console.Write("Nhap ten: ");
            name = Console.ReadLine();

        }
        public static void inputDiem()
        {
            Console.Write("Nhap diem Toan: ");
            a = float.Parse(Console.ReadLine());
            Console.Write("Nhap diem Ly: ");
            b = float.Parse(Console.ReadLine());
            Console.Write("Nhap diem Hoa: ");
            c = float.Parse(Console.ReadLine());
        }

        public static float tong()
        {
            return (float)a + b + c;
        }
        public static float TBC()
        {
            return (float)(a + b + c) / 3;
        }
    }
}

Bai4:
using System;

namespace Lession6
{
    class Bai4
    {
        public static int n { get; set; }
        public static void Main(String[] agrs)
        {
            int chosse;
            do
            {
                showMenu();
                chosse = Convert.ToInt32(Console.ReadLine());
                switch (chosse)
                {
                    case 1:
                        input();
                        break;
                    case 2:
                        Console.WriteLine("Tong cac so tu 1 -> n la: {0}", tong());
                        break;
                    case 3:
                        if (checkSNT(n))
                        {
                            Console.WriteLine("{0} la 1 so nguyen to!!", n);
                        }
                        else
                        {
                            Console.WriteLine("{0} khong phai la 1 so nguyen to!!", n);
                        }
                        break;
                    case 4:
                        if (checkSHH(n))
                        {
                            Console.WriteLine("{0} la 1 so hoan hao!!", n);
                        }
                        else
                        {
                            Console.WriteLine("{0} khong phai la 1 so hoan hao!!", n);
                        }
                        break;
                    case 5:
                        inputNguyenTo(n);

                        break;
                    case 6:
                        inputHoanHao(n);

                        break;
                    case 7:
                        PhanTich(n);
                        break;
                    case 8:
                        Console.Write("Thoat!!!!");
                        break;
                    default:
                        Console.Write("Nhap sai!!! Moi nhap lai......");
                        break;
                }
            } while (chosse != 7);

            Console.ReadKey();
        }

        public static void showMenu()
        {
            Console.WriteLine("\t\t\t MeNU");
            Console.WriteLine("1.      Nhập vào một số nguyên dương n.");
            Console.WriteLine("2.      Tính tổng các số từ 1 đến n");
            Console.WriteLine("3.      Kiểm tra n có là số nguyên tố");
            Console.WriteLine("4.      Kiểm tra n có là số hoàn hảo.");
            Console.WriteLine("5.      In ra các số nguyên tố từ 1 đến n");
            Console.WriteLine("6.      In ra các số hoàn hảo từ 1 đến n.");
            Console.WriteLine("7.      Hiển thị số n thành tích các thừa số nguyên tố.");
            Console.WriteLine("8.      Thoát.");
            Console.Write("Chon: ");
        }

        public static void input()
        {
            for(; ; )
            {
                Console.Write("Nhap so n: ");
                n = int.Parse(Console.ReadLine());
                if (n > 0)
                    break;
                Console.WriteLine("Nhap sai!!!! Moi nhap lai");
            }
        }

        public static int tong()
        {
            int tong = 0;
            for (int i = 1; i <= n; i++ )
            {
                tong += i;
            }
            return tong;
        }
        public static bool checkSNT(int n)
        {
            if (n <= 1)
            {
                return false;
            }
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

        public static bool checkSHH(int n)
        {
            int sum = 0;
            for (int i = 1; i <= n / 2; i++)
            {
                if (n % i == 0)
                    sum += i;
            }
            if (sum == n) return true;
            return false;
        }

        public static void inputNguyenTo(int n)
        {
            Console.Write("Cac so nguyen to tu 1 -> n la :");
            for (int i = 1; i < n; i++)
            {
                if (checkSNT(i))
                {
                    Console.Write("{0}, ", i);
                }
            }
        }

        public static void inputHoanHao(int n)
        {
            Console.Write("Cac so hoan hao tu 1 -> n la :");
            for (int i = 1; i < n; i++)
            {
                if (checkSHH(i))
                {
                    Console.Write("{0}, ", i);
                }
            }
        }

        public static void PhanTich(int n)
        {
            Console.Write("{0} = ",n);
            for (int i = 2; i <= n; i++)
            {
                for (int j = i; ;)
                {
                    if (n % j == 0 && checkSNT(j))
                    {
                        Console.Write("{0} * ",j);
                        n /= j;
                    }
                    else
                        break;
                }
            }
        }


    }
}



lê văn phương [T1907A]
lê văn phương

2020-05-24 04:01:22



// bài 3


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace baitap3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            int num1, num2, num3, opt;
            Console.WriteLine("Nhập vào họ tên của bạn : ");
            Console.ReadLine();
            Console.WriteLine("\nNhập vào điểm môn toán, lý, hóa : ");
           
            Console.WriteLine("Điểm môn toán : ");
            num1 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Điểm môn lý : ");
            num2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Điểm môn hóa : ");
            num3 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Phép tính muốn chọn : ");
            Console.Write("\n1: Tính tổng 3 môn :  \n2: Tính trung bình 3 môn : \n3: Thoát!! \n");
            Console.Write("Lựa chọn của bạn : ");
            opt = Convert.ToInt32(Console.ReadLine());

            switch (opt)
            {
                case 1:
                    Console.WriteLine("\nTính tổng 3 môn toán, lý, hóa :\n    {0} + {1} + {2} = {3}", num1,num2,num3,num1+num2+num3);
                    break;
                case 2:
                    Console.WriteLine("Tính trung bình 3 môn toán, lý, hóa :\n     ( {0} + {1} + {2} ) / 3 = {3}", num1, num2, num3, (num1 + num2 + num3)/3);
                    break;
                case 3:
                   
                    break;
                default:
                    Console.WriteLine("Nhập hợp lệ !!!");
                    break;
            }


            Console.ReadKey();
        }
    }
}



lê văn phương [T1907A]
lê văn phương

2020-05-24 03:27:40



// bài 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bai1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            
            Input();
            Console.ReadKey();
        }
        public static void Input()
        {
            Console.Write("Mời bạn nhập tên : ");
            string a=Console.ReadLine();
            Console.WriteLine("\nTên bạn mới nhập : {0}",a);
        }
    }
}



// bài 2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bai2
{
    class Program
    {
        public static void Main()
        {
            Console.OutputEncoding = Encoding.UTF8;
            int num1, num2, opt;

            Console.Write("\n");
            Console.Write("Nhập vào 2 số nguyên :\n");
            Console.Write("------------------------------------------------");
            Console.Write("\n\n");


            Console.Write("Nhập vào số nguyên thứ nhất : ");
            num1 = Convert.ToInt32(Console.ReadLine());
            Console.Write("Nhập vào số nguyên thứ hai : ");
            num2 = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("\nSố vừa nhập {0} và {1}",num1,num2);


            Console.Write("\nPhép tính muốn chọn :\n");
            Console.Write("1 - Phép cộng.\n2 - Phép trừ.\n3 -Phép nhân.\n4 - Phép chia.\n5 - Thoát.\n");
            Console.Write("\nNhập lựa chọn của bạn : ");
            opt = Convert.ToInt32(Console.ReadLine());

            switch (opt)
            {
                case 1:
                    Console.Write("Tổng hai số {0} và {1} là: {2}\n", num1, num2, num1 + num2);
                    break;

                case 2:
                    Console.Write("Hiệu của hai số {0} và {1} là: {2}\n", num1, num2, num1 - num2);
                    break;

                case 3:
                    Console.Write("Tích của {0} và {1} là: {2}\n", num1, num2, num1 * num2);
                    break;

                case 4:
                    if (num2 == 0)
                    {
                        Console.Write("Nếu số thứ 2 = 0 --> Không thể thực hiện được phép chia cho 0.\n");
                    }
                    else
                    {
                        Console.Write("Thương của {0} và {1} là: {2}\n", num1, num2, num1 / num2);
                    }
                    break;

                case 5:
                    break;

                default:
                    Console.Write("Nhập tùy chọn hợp lệ\n");
                    break;
            }

            Console.ReadKey();
        }
    }
}