static double InputNumber(string label, int condition = 0)
Console.Write($"Nhap {label}: ");
txt = Console.ReadLine();
if (condition == 1 && txt == "0")
Console.WriteLine($"{label} phải khác 0");
return InputNumber(label);
if (Double.TryParse(txt, out number))
Console.WriteLine("Vui lòng nhập số tự nhiên.");
return InputNumber(label);
static int InputInt(string label, int condition = 0)
Console.Write($"Nhap {label}: ");
txt = Console.ReadLine();
if (condition == 1 && txt == "0")
Console.WriteLine($"{label} phải khác 0");
if (int.TryParse(txt, out number))
Console.WriteLine("Vui lòng nhập số tự nguyên.");
static void Ex1(int n = 1)
Console.WriteLine($"i {i}");
Console.WriteLine($"S trước {S}");
Console.WriteLine($"step {step}");
Console.WriteLine($"S sau {S}");
Console.WriteLine($"Kết quả S({n}): {S}");
static void Ex2(int x = 0, int n = 1)
Console.WriteLine($"Kết quả S({n}): {S}");
static void Ex3(int x = 0, int n = 1)
S += Math.Pow(x, (2 * i));
Console.WriteLine($"Kết quả S({n}): {S}");
static void Ex4(int x = 0, int n = 1)
S += Math.Pow(x, (2 * i + 1));
Console.WriteLine($"Kết quả S({n}): {S}");
static void Ex5(int n = 1)
Console.WriteLine("Hỏi lại đề");
static void Ex6(int n = 1)
Console.WriteLine("Hỏi lại đề");
static void Ex7(int x = 1, int n = 1)
S += Math.Pow(x, i) / sample;
Console.WriteLine($"Kết quả S({n}): {S}");
static void Ex8(int x = 1, int n = 1)
S += Math.Pow(x, 2 * i) / sample;
Console.WriteLine($"Kết quả S({n}): {S}");
static void Ex9(int x = 1, int n = 1)
S += Math.Pow(x, 2 * i + 1) / sample;
Console.WriteLine($"Kết quả S({n}): {S}");
static void Ex10(int n = 1)
public static void Main()
Console.WriteLine("Hãy chọn loại bài tập.");
Console.WriteLine("11. Tính S(n) = 1 + 1.2 + 1.2.3 + … + 1.2.3….N");
Console.WriteLine("12. Tính S(n) = x + x^2 + x^3 + … + x^n");
Console.WriteLine("13. Tính S(n) = x^2 + x^4 + … + x^2n");
Console.WriteLine("14. Tính S(n) = x + x^3 + x^5 + … + x^2n + 1");
Console.WriteLine("15. Tính S(n) = 1 + 1/1 + 2 + 1/ 1 + 2 + 3 + ….. + 1/ 1 + 2 + 3 + …. + N");
Console.WriteLine("16. Tính S(n) = x + x^2/1 + 2 + x^3/1 + 2 + 3 + … + x^n/1 + 2 + 3 + …. + N");
Console.WriteLine("17. Tính S(n) = x + x^2/2! + x^3/3! + … + x^n/N!");
Console.WriteLine("18. Tính S(n) = 1 + x^2/2! + x^4/4! + … + x^2n/(2n)!");
Console.WriteLine("19. Tính S(n) = 1 + x + x^3/3! + x^5/5! + … + x^(2n+1)/(2n+1)!");
Console.WriteLine("20. Liệt kê tất cả các “ước số” của số nguyên dương n");
Console.WriteLine("==================");
Console.Write("Chọn bài số: ");
numberSelect = Console.ReadLine();
Console.WriteLine("---- 11. Tính S(n) = 1 + 1.2 + 1.2.3 + … + 1.2.3….N ----");
Console.WriteLine("---- 12. Tính S(n) = x + x^2 + x^3 + … + x^n ----");
Ex2(InputInt("x"), InputInt("n"));
Console.WriteLine("---- 13. Tính S(n) = x^2 + x^4 + … + x^2n -----");
Ex3(InputInt("x"), InputInt("n"));
Console.WriteLine("---- 14. Tính S(n) = x + x^3 + x^5 + … + x^2n + 1 -----");
Ex4(InputInt("x"), InputInt("n"));
Console.WriteLine("---- 15. Tính S(n) = 1 + 1/1 + 2 + 1/ 1 + 2 + 3 + ….. + 1/ 1 + 2 + 3 + …. + N -----");
Console.WriteLine("---- 16. Tính S(n) = x + x^2/1 + 2 + x^3/1 + 2 + 3 + … + x^n/1 + 2 + 3 + …. + N -----");
Console.WriteLine("---- 17. Tính S(n) = x + x^2/2! + x^3/3! + … + x^n/N! -----");
Ex7(InputInt("x"), InputInt("n"));
Console.WriteLine("---- 18. Tính S(n) = 1 + x^2/2! + x^4/4! + … + x^2n/(2n)! -----");
Ex8(InputInt("x"), InputInt("n"));
Console.WriteLine("---- 19. Tính S(n) = 1 + x + x^3/3! + x^5/5! + … + x^(2n+1)/(2n+1)! -----");
Ex9(InputInt("x"), InputInt("n"));
Console.WriteLine("---- 20. Liệt kê tất cả các “ước số” của số nguyên dương n -----");
Console.WriteLine("Tạm biệt!");