Bài giải 76 bài tập VBnet cho anh em tham khảo
- Lưu ý: Chờ sau 5s, Click BỎ QUA QUẢNG CÁO (SKIP AD)
bài 1:tính tổng S=1+2+3+...+n
| Code: |
Module Module1
Function Tong(ByVal n As Integer) As Integer Dim S As Integer = 0 Dim i As Integer For i = 0 To n Step 1 S = S + i Next Return S End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Integer = 10 kq = Tong(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 2: S=1^2+2^2+3^2+.....n^n
| Code: |
Module Module1
Function Tong(ByVal n As Integer) As Integer Dim S As Integer = 0 Dim i As Integer For i = 0 To n Step 1 S = S + i * i Next Return S End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Integer kq = Tong(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 3: S= 1+1/2+1/3+...+1/n
| Code: |
Module Module1
Function Tong(ByVal n As Integer) As Double Dim S As Double = 0 Dim i As Integer For i = 1 To n Step 1 S = S + (1 / i) Next Return S End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 4: S= 1/2 + 1/4 +...+1/2n
| Code: |
Module Module1 Function Tong(ByVal n As Integer) As Double Dim S As Double = 0 Dim i As Integer For i = 1 To n Step 1 S = S + 1 / (2 * i) Next Return S End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 5: S= 1+ 1/3 + 1/5+..+1/2n+1
| Code: |
Module Module1 Function Tong(ByVal n As Integer) As Double Dim S As Double = 1 Dim i As Integer For i = 1 To n Step 1 S = S + 1 / (2 * i + 1) Next Return S End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 6: S=1/1*2 + 1/2*3 +...+1/n*(n+1)
| Code: |
Module Module1 Function Tong(ByVal n As Integer) As Double Dim S As Double = 0 Dim i As Integer For i = 1 To n Step 1 S = S + 1 / (i * (i + 1)) Next Return S End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 7: S=1/2 +2/3+..+n/n+1
| Code: |
Module Module1 Function Tong(ByVal n As Integer) As Double Dim S As Double = 0 Dim i As Integer For i = 1 To n Step 1 S = S + i / (i + 1) Next Return S End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 8: S=1/2 +3/4+..+2n+1/2n+1
| Code: |
Module Module1 Function Tong(ByVal n As Integer) As Double Dim S As Double = 0 Dim i As Integer For i = 0 To n Step 1 S = S + (2 * i + 1) / (2 * i + 2) Next Return S End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 9: T= 1*2*3*...*n
| Code: |
Module Module1 Function Tich(ByVal n As Integer) As Integer Dim T As Integer = 1 Dim i As Integer For i = 1 To n Step 1 T = T * i Next Return T End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tich(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 10: T =x^n
| Code: |
Module Module1 Function LuyThua(ByVal x As Double, ByVal n As Integer) As Double Dim T As Double T = x ^ n Return T End Function Sub Main() Dim n, x As Integer Console.WriteLine("Nhap Vao So x: ") x = Console.ReadLine() Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = LuyThua(x, n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 11: S= 1+1*2+ 1*2*3+..+1*2*3*..*n
| Code: |
Module Module1 Function TongTich(ByVal n As Integer) As Integer Dim T As Integer = 1 Dim S As Integer = 0 Dim i As Integer For i = 1 To n Step 1 T = T * i S = S + T Next Return S End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Integer kq = TongTich(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 12: S=x+x^2 + x^3 +...+x^n
| Code: |
Module Module1 Function TongMu(ByVal x As Double, ByVal n As Integer) As Double Dim T As Integer = 1 Dim S As Integer = 0 Dim i As Integer For i = 1 To n Step 1 T = x ^ i S = S + T Next Return S End Function Sub Main() Dim n, x As Integer Console.WriteLine("Nhap Vao So x: ") x = Console.ReadLine() Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = TongMu(x, n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 13: S=x^2 + x^4 +...+x^2n
| Code: |
Module Module1 Function TongMu(ByVal x As Double, ByVal n As Integer) As Double Dim T As Integer = 1 Dim S As Integer = 0 Dim i As Integer For i = 1 To n Step 1 T = x ^ (2 * i) S = S + T Next Return S End Function Sub Main() Dim n, x As Integer Console.WriteLine("Nhap Vao So x: ") x = Console.ReadLine() Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = TongMu(x, n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 14: S=x + x^3 + x^5 +...+x^2n+1
| Code: |
Module Module1 Function TongMu(ByVal x As Double, ByVal n As Integer) As Double Dim T As Integer = 1 Dim S As Integer = 0 Dim i As Integer For i = 0 To n Step 1 T = x ^ (2 * i + 1) S = S + T Next Return S End Function Sub Main() Dim n, x As Integer Console.WriteLine("Nhap Vao So x: ") x = Console.ReadLine() Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = TongMu(x, n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 15: S=1 +1 /(1+2) +1 /(1+2+3)+...+1/(1+2+3+..+n)
| Code: |
Module Module1 Function Tong(ByVal n As Integer) As Double Dim S As Double = 0 Dim M As Integer = 0 Dim i As Integer For i = 1 To n Step 1 M = M + i S = S + (1 / M) Next Return S End Function Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 16: S=x +x^2 /(1+2) +x^3 /(1+2+3)+...+x^n/(1+2+3+..+n)
| Code: |
Module Module1 Function Tong(ByVal x As Double, ByVal n As Integer) As Double Dim S As Double = 0 Dim M As Integer = 0 Dim i As Integer For i = 1 To n Step 1 M = M + i S = S + (x ^ i) / M Next Return S End Function Sub Main() Dim x As Integer Console.WriteLine("Nhap Vao So x: ") x = Console.ReadLine() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(x, n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 17: S=x +x^2 /2! +x^3 /3!+...+x^n/n!
| Code: |
Module Module1 Function Tong(ByVal x As Double, ByVal n As Integer) As Double Dim S As Double = 0 Dim M As Integer = 1 Dim i As Integer For i = 1 To n Step 1 M = M * i S = S + (x ^ i) / M Next Return S End Function Sub Main() Dim x As Integer Console.WriteLine("Nhap Vao So x: ") x = Console.ReadLine() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(x, n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 18: S=1 +x^2 /2! +x^4 /4!+...+x^2n/(2n)!
| Code: |
Module Module1 Function Tong(ByVal x As Double, ByVal n As Integer) As Double Dim S As Double = 1 Dim M As Integer = 1 Dim T As Double = x Dim i As Integer For i = 2 To 2 * n Step 2 T = x ^ i M = M * (i - 1) * i S = S + T / M Next Return S End Function Sub Main() Dim x As Integer Console.WriteLine("Nhap Vao So x: ") x = Console.ReadLine() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(x, n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
Bài 19: S=1 +x +x^3 /3! +x^5/5!+...+x^2n+1/(2n+1)!
| Code: |
Module Module1 Function Tong(ByVal x As Double, ByVal n As Integer) As Double Dim S As Double = 1 + x Dim M As Integer = 1 Dim T As Double = x Dim i As Integer For i = 3 To 2 * n + 1 Step 2 T = x ^ i M = M * i * (i - 1) S = S + T / M Next Return S End Function Sub Main() Dim x As Integer Console.WriteLine("Nhap Vao So x: ") x = Console.ReadLine() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Double kq = Tong(x, n) Console.WriteLine("Ket qua : " & kq) End Sub End Module |
bai 20:liệt kê tất cả các ước số của số nguyên dương:
| Code: |
Module Module1 Sub UocSo(ByVal n As Integer) Dim i As Integer For i = 1 To n Step 1 If (n Mod i = 0) Then Console.Write(i & " ") End If Next End Sub Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() Console.WriteLine("Tat Ca Cac Uoc So Cua {0}: ", n) UocSo(n) End Sub End Module |
bai 21:Tính Tổng tất cả các ước số của số nguyên dương:
| Code: |
Module Module1
Function TongUocSo(ByVal n As Integer) As Integer Dim S As Integer Dim i As Integer For i = 1 To n Step 1 If (n Mod i = 0) Then S = S + i End If Next Return S End Function Sub Main() Dim n, kq As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongUocSo(n) Console.WriteLine("Tong Tat Ca Cac Uoc So Cua {0}: {1}", n, kq) End Sub End Module |
bai 22:Tính Tích tất cả các ước số của số nguyên dương:
| Code: |
Module Module1 Function TichUocSo(ByVal n As Integer) As Integer Dim T As Integer = 1 Dim i As Integer For i = 1 To n Step 1 If (n Mod i = 0) Then T = T * i End If Next Return T End Function Sub Main() Dim n, kq As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TichUocSo(n) Console.WriteLine("Tich Tat Ca Cac Uoc So Cua {0}: {1}", n, kq) End Sub End Module |
bai 23:Đếm Số Lượng ước số của số nguyên dương:
| Code: |
Module Module1 Function DemUocSo(ByVal n As Integer) As Integer Dim D As Integer Dim i As Integer For i = 1 To n Step 1 If (n Mod i = 0) Then D += 1 End If Next Return D End Function Sub Main() Dim n, kq As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = DemUocSo(n) Console.WriteLine(" So Luong Uoc So Cua {0}: {1}", n, kq) End Sub End Module |
bai 24:Liệt kê tất cả các ước số của số nguyên dương:
| Code: |
Module Module1 Sub LietKeUocSoLe(ByVal n As Integer) Dim i As Integer Console.WriteLine("Tat Ca Cac Uoc So Le Cua {0}: ", n) For i = 1 To n Step 2 If (n Mod i = 0) Then Console.Write(i & " ") End If Next End Sub Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() LietKeUocSoLe(n) End Sub End Module |
bai 25:Tính Tổng tất cả các "ước số chẵn"của số nguyên dương:
| Code: |
Module Module1 Sub LietKeUocSoChan(ByVal n As Integer) Dim i As Integer Console.WriteLine("Tat Ca Cac Uoc So Chan Cua {0}: ", n) For i = 2 To n Step 2 If (n Mod i = 0) Then Console.Write(i & " ") End If Next End Sub Sub Main() Dim n As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() LietKeUocSoChan(n) End Sub End Module |
bai 26:Tính Tích tất cả các "ước số lẽ"của số nguyên dương:
| Code: |
Module Module1 Function TichUocSoLe(ByVal n As Integer) As Integer Dim T As Integer = 1 Dim i As Integer For i = 1 To n Step 2 If (n Mod i = 0) Then T = T * i End If Next Return T End Function Sub Main() Dim n, kq As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TichUocSoLe(n) Console.WriteLine("Tich Tat Ca Cac Uoc So Le Cua {0}: {1}", n, kq) End Sub End Module |
bai 27:Đếm số lượng "ước số chẵn"của số nguyên dương:
| Code: |
Module Module1
Function DemUocSo(ByVal n As Integer) As Integer Dim D As Integer Dim i As Integer For i = 2 To n Step 2 If (n Mod i = 0) Then D += 1 End If Next Return D End Function Sub Main() Dim n, kq As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = DemUocSo(n) Console.WriteLine(" So Luong Uoc So Chan Cua {0}: {1}", n, kq) End Sub End Module |
bài 28:Cho số nguyên dương N ,tính tổng các số nguyên dương nhỏ hơn chính nó
| Code: |
Module Module1 Function TongUocSo(ByVal n As Integer) As Integer Dim S As Integer Dim i As Integer For i = 1 To n - 1 Step 1 If (n Mod i = 0) Then S = S + i End If Next Return S End Function Sub Main() Dim n, kq As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongUocSo(n) Console.WriteLine("Tong Tat Ca Cac Uoc So Nho Hon {0}: {1}", n, kq) End Sub End Module |
bài 29:tìm ước số lẽ lớn nhất của số nguyện dương N
| Code: |
Module Module1
Function TongUocSo(ByVal n As Integer) As Integer Dim T As Integer Dim i As Integer For i = 1 To n - 1 Step 2 If (n Mod i = 0) Then T = i End If Next Return T End Function Sub Main() Dim n, kq As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongUocSo(n) Console.WriteLine("Uoc So Le Lon Nhat Cua {0}: {1}", n, kq) End Sub End Module |
Bài 30: kiểm tra số nguyên dương N có phả số Hoàn thiện KÔ
| Code: |
Module Module1 Function KTHoanThien(ByVal n As Integer) As Integer Dim S As Integer Dim i As Integer For i = 1 To n - 1 Step 1 If (n Mod i = 0) Then S = S + i End If Next If S = n Then Return 1 Else Return 0 End If End Function Sub Main() Dim n, kq As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = KTHoanThien(n) If kq = 1 Then Console.WriteLine("{0} La So Hoan Thien ", n) Else Console.WriteLine("{0} Khong La So Hoan Thien ", n) End If End Sub End Module |
Bài 32: kiểm tra số nguyên dương N có phả số Chính Phương KÔ
| Code: |
Module Module1 Function KTChinhPhuong(ByVal n As Integer) As Integer Dim D As Integer Dim i As Integer For i = 1 To n Step 1 D = i * i If D = n Then Return 1 End If Next Return 0 End Function Sub Main() Dim n, kq As Integer Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = KTChinhPhuong(n) If kq = 1 Then Console.WriteLine("{0} La So Chinh Phuong ", n) Else Console.WriteLine("{0} Khong La So Chinh Phuong", n) End If End Sub End Module |
bài 33: Tổng Căn Bậc 2
| Code: |
Module Module1 Function TongCan(ByVal n As Integer) As Double Dim S As Double = 0 Dim i As Integer For i = 1 To n Step 1 S = Math.Sqrt(2 + S) Next Return S End Function Sub Main() Dim n As Integer Dim kq As Double Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongCan(n) Console.WriteLine("Ket Qua : {0}", kq) End Sub End Module |
bài 34:
| Code: |
Module Module1 Function TongCan(ByVal n As Integer) As Double Dim S As Double = 0 Dim i As Integer For i = 1 To n Step 1 S = Math.Sqrt(i + S) Next Return S End Function Sub Main() Dim n As Integer Dim kq As Double Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongCan(n) Console.WriteLine("Ket Qua : {0}", kq) End Sub End Module |
bài 35:
PHP Code:[URL="http://&page=3"] ( Bôi đen tất cả nội dung [/URL]
| Code: |
Module Module1 Function TongCan(ByVal n As Integer) As Double Dim S As Double = 0 Dim i As Integer For i = n To 1 Step -1 S = Math.Sqrt(i + S) Next Return S End Function Sub Main() Dim n As Integer Dim kq As Double Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongCan(n) Console.WriteLine("Ket Qua : {0}", kq) End Sub End Module |
bài 36:
| Code: |
Module Module1 Function TongCan(ByVal n As Integer) As Double Dim S As Double Dim T As Integer = 1 Dim i As Integer For i = 1 To n Step 1 T = T * i S = Math.Sqrt(T + S) Next Return S End Function Sub Main() Dim n As Integer Dim kq As Double Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongCan(n) Console.WriteLine("Ket Qua : {0}", kq) End Sub End Module |
bài 37
| Code: |
Module Module1 Function TongCan(ByVal n As Integer) As Double Dim S As Double Dim i As Integer For i = 2 To n Step 1 S = Math.Pow(i + S, 1 / i) Next Return S End Function Sub Main() Dim n As Integer Dim kq As Double Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongCan(n) kq = Math.Pow(4.41, 1 / 3) Console.WriteLine("Ket Qua : {0}", kq) End Sub End Module |
bài 38
| Code: |
Module Module1 Function TongCan(ByVal n As Integer) As Double Dim S As Double Dim i As Integer For i = 1 To n Step 1 S = Math.Pow(i + S, 1 / (i + 1)) Next Return S End Function Sub Main() Dim n As Integer Dim kq As Double Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongCan(n) Console.WriteLine("Ket Qua : {0}", kq) End Sub End Module |
bài 39
| Code: |
Module Module1 Function TongCan(ByVal n As Integer) As Double Dim S As Double Dim i As Integer Dim T As Integer = 1 For i = 1 To n Step 1 T = T * i S = Math.Pow(T + S, 1 / (i + 1)) Next Return S End Function Sub Main() Dim n As Integer Dim kq As Double Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongCan(n) Console.WriteLine("Ket Qua : {0}", kq) End Sub End Module |
bài 40:
| Code: |
Module Module1 Function TongCan(ByVal x As Single, ByVal n As Integer) As Double Dim S As Double Dim i As Integer Dim T As Single = 1 For i = 1 To n Step 1 T = T * x S = Math.Sqrt(T + S) Next Return S End Function Sub Main() Dim n As Integer Dim x As Single Dim kq As Double Console.WriteLine("Nhap Vao So x: ") x = Console.ReadLine() Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongCan(x, n) Console.WriteLine("Ket Qua : {0}", kq) End Sub End Module |
bài 41:
| Code: |
Module Module1 Function TongPS(ByVal n As Integer) As Double Dim S As Double = 1 + 1 / 2 Dim i As Integer Dim T As Single = 1 For i = 2 To n Step 1 S = 1 + 1 / S Next Return S End Function Sub Main() Dim n As Integer Dim kq As Double Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongPS(n) Console.WriteLine("Ket Qua : {0}", kq) End Sub End Module |
bài 42 tìm giá trị k lớn nhất sao cho S(k)<n
| Code: |
Module Module1 Function TongCan(ByVal n As Integer) As Double Dim S As Integer Dim i As Integer For i = 1 To n Step 1 S = S + i If S >= n Then Return i - 1 End If Next End Function Sub Main() Dim n As Integer Dim kq As Double Console.WriteLine("Nhap Vao So n: ") n = Console.ReadLine() kq = TongCan(n) Console.WriteLine("So Nguyen Duong Thoa : {0}", kq) End Sub End Module |
bài 43 :Đếm số lượng chữ số của số nguyên dương
| Code: |
Module Module1 Public Function DemSL(ByVal n As Integer) As Integer Dim D As Integer Dim T As Integer While n <> 0 T = n Mod 10 If T <> 0 Then D = D + 1 End If n = n \ 10 End While Return D End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = DemSL(n) Console.WriteLine("So Luong Chu So : {0}", kq) End Sub End Module |
bài 44 :Tính Tổng các chữ số của số nguyên dương
| Code: |
Module Module1 Function TongChuSo(ByVal n As Integer) As Integer Dim S As Integer Dim T As Integer While n <> 0 T = n Mod 10 If T <> 0 Then S = S + T End If n = n \ 10 End While Return S End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TongChuSo(n) Console.WriteLine("Tong Chu So : {0}", kq) End Sub End Module |
bài 45 :Tính Tích các chữ số của số nguyên dương
| Code: |
Module Module1 Function TichChuSo(ByVal n As Integer) As Integer Dim T As Integer = 1 Dim Temp As Integer While n <> 0 Temp = n Mod 10 If Temp <> 0 Then T = T * Temp End If n = n \ 10 End While Return T End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TichChuSo(n) Console.WriteLine("Tich Cac Chu So : {0}", kq) End Sub End Module |
bài 46 :Đếm số lượng chữ số lẽ của số nguyên dương
| Code: |
Module Module1 Function DemSoLe(ByVal n As Integer) As Integer Dim D As Integer Dim T As Integer While n <> 0 T = n Mod 10 If T <> 0 Then If T Mod 2 <> 0 Then D = D + 1 End If End If n = n \ 10 End While Return D End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = DemSoLe(n) Console.WriteLine("So Luong Chu So Le: {0}", kq) End Sub End Module |
bài 47 :tính Tổng các chữ số chẵn của số nguyên dương
| Code: |
Module Module1 Function TongSoChan(ByVal n As Integer) As Integer Dim S As Integer Dim T As Integer While n <> 0 T = n Mod 10 If T <> 0 Then If T Mod 2 = 0 Then S = S + T End If End If n = n \ 10 End While Return S End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TongSoChan(n) Console.WriteLine("Tong Chu So Chan: {0}", kq) End Sub End Module |
bài 48 :tính Tích các chữ số chẵn của số nguyên dương
| Code: |
Module Module1 Function TichSoLe(ByVal n As Integer) As Integer Dim S As Integer = 1 Dim T As Integer While n <> 0 T = n Mod 10 If T <> 0 Then If T Mod 2 <> 0 Then S = S * T End If End If n = n \ 10 End While Return S End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TichSoLe(n) Console.WriteLine("Tich Chu So Le: {0}", kq) End Sub End Module |
bài 49: tìm chữ số đầu tiên của N
| Code: |
Module Module1 Function TichSoLe(ByVal n As Integer) As Integer Dim S As Integer = 1 While n > 10 n = n / 10 End While Return n End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TichSoLe(n) Console.WriteLine("Chu So Dau Tien: {0}", kq) End Sub End Module |
bài 50: tìm chữ cố đảo ngược của số nguyên dương
| Code: |
Module Module1 Public Function DemSL(ByVal n As Integer) As Integer Dim D As Integer Dim T As Integer While n <> 0 T = n Mod 10 If T <> 0 Then D = D + 1 End If n = n /10 End While Return D End Function Function KTNghichDao(ByVal n As Integer) As Integer Dim so As Integer = DemSL(n) Dim i As Integer Dim temp As Integer = 1 For i = 2 To so Step 1 temp = temp * 10 Next Dim K As Integer = n Dim S, t As Integer While K <> 0 t = K Mod 10 S = S + t * temp K = K / 10 temp = temp / 10 End While Return S End Function Sub Main() Dim n As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() Dim kq As Integer = KTNghichDao(n) Console.Write("So Nghich Dao: {0}", kq) End Sub End Module |
bài 51: tìm chữ số lớn nhất của số nguyên dương
| Code: |
Module Module1 Function ChuSoLonNhat(ByVal n As Integer) As Integer Dim temp As Integer = 1 Dim T As Integer While n <> 0 T = n Mod 10 If T > temp Then temp = T End If n = n / 10 End While Return temp End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = ChuSoLonNhat(n) Console.WriteLine("Chu So Lon Nhat: {0}", kq) End Sub End Module |
bài 52: tìm chữ số Nhỏ nhất của số nguyên dương
| Code: |
Module Module1 Function ChuSoNhoNhat(ByVal n As Integer) As Integer Dim temp As Integer = 9 Dim T As Integer While n <> 0 T = n Mod 10 If T < temp Then temp = T End If n = n / 10 End While Return temp End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = ChuSoNhoNhat(n) Console.WriteLine("Chu So Nho Nhat: {0}", kq) End Sub End Module |
bài 53: Đếm SL chữ số lớn nhất của số nguyên dương
| Code: |
Module Module1 Function ChuSoNhoNhat(ByVal n As Integer) As Integer Dim temp As Integer = 1 Dim T As Integer Dim D As Integer Dim k = n While k <> 0 T = k Mod 10 If T > temp Then temp = T End If k = k / 10 End While While n <> 0 T = n Mod 10 If T = temp Then D = D + 1 End If n = n / 10 End While Return D End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = ChuSoNhoNhat(n) Console.WriteLine("So Luong Chu So Lon Nhat: {0}", kq) End Sub End Module |
bài 54: Đếm SL chữ số Nhỏ nhất của số nguyên dương
tương tự bài 53 thay điều kien chj3 khác đK If T < temp Then
bài 55 Đếm sl chữ số đầu tiên của so nguyên dương
| Code: |
Module Module1 Function SoDauTien(ByVal n As Integer) As Integer Dim S As Integer = 1 Dim t As Integer = n Dim temp, D As Integer While t > 10 t = t / 10 End While While n <> 0 temp = n Mod 10 If temp = t Then D = D + 1 End If n = n / 10 End While Return D End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = SoDauTien(n) Console.WriteLine("So Luong Chu So Dau Tien: {0}", kq) End Sub End Module |
bài 56: kjem tra số Nguyên dương có toàn chữ số lẽ hay kô
| Code: |
Module Module1 Function KTToanLe(ByVal n As Integer) As Integer Dim t As Integer = n Dim k As Integer While t <> 0 k = t Mod 10 If k Mod 2 = 0 Then Return 0 End If t = t / 10 End While Return 1 End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = KTToanLe(n) If kq = 1 Then Console.WriteLine("Toan Chu So Le") Else Console.WriteLine("Khong Phai Toan Le") End If End Sub End Module |
bài 57: kjem tra số Nguyên dương có toàn chữ số Chẵn hay kô
| Code: |
Module Module1 Function KTToanChan(ByVal n As Integer) As Integer Dim t As Integer = n Dim k As Integer While t <> 0 k = t Mod 10 If k Mod 2 <> 0 Then Return 0 End If t = t / 10 End While Return 1 End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = KTToanChan(n) If kq = 1 Then Console.WriteLine("Toan Chu So Chan") Else Console.WriteLine("Khong Phai Toan Chan") End If End Sub End Module |
bài 59:kiễm tra số nguyên dương N có phải là số Đối xứng kô
| Code: |
Module Module1 Public Function DemSL(ByVal n As Integer) As Integer Dim D As Integer Dim T As Integer While n <> 0 T = n Mod 10 If T <> 0 Then D = D + 1 End If n = n \ 10 End While Return D End Function Function KTNghichDao(ByVal n As Integer) As Integer Dim so As Integer = DemSL(n) Dim i As Integer Dim temp As Integer = 1 For i = 2 To so Step 1 temp = temp * 10 Next Dim K As Integer = n Dim S, t As Integer While K <> 0 t = K Mod 10 S = S + t * temp K = K \ 10 temp = temp \ 10 End While Return S End Function Function KTDoiXung(ByVal n As Integer) As Integer Dim sl As Integer = DemSL(n) If sl Mod 2 = 0 Then Return 0 End If Dim ND As Integer = KTNghichDao(n) If ND = n Then Return 1 End If Return 0 End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = KTDoiXung(n) If kq = 1 Then Console.WriteLine("So Doi Xung ") Else Console.WriteLine("So Khong Doi Xung ") End If End Sub End Module |
bài 60: KT số Nguyen dương (N)có tăng dần từ trái sang phải hay kô
| Code: |
Module Module1 Function KTTangDan(ByVal n As Integer) As Integer Dim k As Integer = n Dim temp As Integer = k Mod 10 k = k / 10 Dim t As Integer While k <> 0 t = k Mod 10 If t > temp Then Return 0 Else temp = t End If k = k / 10 End While Return 1 End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = KTTangDan(n) If kq = 1 Then Console.WriteLine("Tang Dan tu Trai Sang Phai ") Else Console.WriteLine("Khong Tang Dan Tu Trai Sang Phai ") End If End Sub End Module |
bài 61: KT số Nguyen dương (N)có Giảm dần từ trái sang phải hay kô
| Code: |
Module Module1 Function KTGiamDan(ByVal n As Integer) As Integer Dim k As Integer = n Dim temp As Integer = k Mod 10 k = k \ 10 Dim t As Integer While k <> 0 t = k Mod 10 If t < temp Then Return 0 Else temp = t End If k = k \ 10 End While Return 1 End Function Sub Main() Dim n As Integer Dim kq As Integer Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = KTGiamDan(n) If kq = 1 Then Console.WriteLine("Giam Dan tu Trai Sang Phai ") Else Console.WriteLine("Khong Giam Dan Tu Trai Sang Phai ") End If End Sub End Module |
bài 62 Tìm Ước Chung Lớn Nhất
| Code: |
Module Module1 Function UocChungLonNhat(ByVal a As Integer, ByVal b As Integer) As Integer Dim t1 As Integer = a Dim t2 As Integer = b While t1 <> t2 If t1 > t2 Then t1 = t1 - t2 Else t2 = t2 - t1 End If End While Return t1 End Function Sub Main() Dim a, b As Integer Dim kq As Integer Console.Write("Nhap Vao So a: ") a = Console.ReadLine() Console.Write("Nhap Vao So b: ") b = Console.ReadLine() kq = UocChungLonNhat(a, b) Console.WriteLine("Uoc Chung Lon Nhat : {0}", kq) End Sub End Module |
bài 63 tìm Bội chung nhỏ Nhất
| Code: |
Module Module1 Function BoiChungNhoNhat(ByVal a As Integer, ByVal b As Integer) As Integer Dim t1 As Integer = a Dim t2 As Integer = b While t1 <> t2 If t1 > t2 Then t1 = t1 - t2 Else t2 = t2 - t1 End If End While Dim kq = a * b / t1 Return kq End Function Sub Main() Dim a, b As Integer Dim kq As Integer Console.Write("Nhap Vao So a: ") a = Console.ReadLine() Console.Write("Nhap Vao So b: ") b = Console.ReadLine() kq = BoiChungNhoNhat(a, b) Console.WriteLine("Boi Chung Nho Nhat : {0}", kq) End Sub End Module |
bài 64 Giải PT bậc 1
| Code: |
Module Module1 Sub PTBac1(ByVal a As Integer, ByVal b As Integer) If a = 0 Then If b = 0 Then Console.WriteLine("Phuong Trinh Vo So Nghiem") Exit Sub Else Console.WriteLine("Phuong Trinh Vo Nghiem") Exit Sub End If Else Console.WriteLine("Nghiem X= {0}", -b / a) End If End Sub Sub Main() Dim a, b As Integer Console.Write("Nhap Vao So a: ") a = Console.ReadLine() Console.Write("Nhap Vao So b: ") b = Console.ReadLine() PTBac1(a, b) End Sub End Module |
Bài 65 Giải PT bậc 2
| Code: |
Module Module1 Sub PTBac1(ByVal a As Integer, ByVal b As Integer) If a = 0 Then If b = 0 Then Console.WriteLine("Phuong Trinh Vo So Nghiem") Exit Sub Else Console.WriteLine("Phuong Trinh Vo Nghiem") Exit Sub End If Else Console.WriteLine("Nghiem X= {0}", -b / a) End If End Sub Sub PTBac2(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) If a = 0 Then PTBac1(b, c) Else Dim Delta As Double = b * b - 4 * a * c If Delta < 0 Then Console.WriteLine("Phuong Trinh Vo Nghiem") ElseIf Delta = 0 Then Console.WriteLine("Phuong Trinh Co Nghiem Kep X= {0}", -b / 2 * a) Else Console.WriteLine("Phuong Trinh Co 2 Nghiem \nX1= {0} X2={1}", (-b + Math.Sqrt(Delta)) / 2 * a, (-b - Math.Sqrt(Delta)) / 2 * a) End If End If End Sub Sub Main() Dim a, b, c As Integer Console.Write("Nhap Vao So a: ") a = Console.ReadLine() Console.Write("Nhap Vao So b: ") b = Console.ReadLine() Console.Write("Nhap Vao So c: ") c = Console.ReadLine() PTBac2(a, b, c) End Sub End Module |
Bài 66 Giải PT bậc 4
| Code: |
Module Module1 Sub PTBac1(ByVal a As Integer, ByVal b As Integer) If a = 0 Then If b = 0 Then Console.WriteLine("Phuong Trinh Vo So Nghiem") Exit Sub Else Console.WriteLine("Phuong Trinh Vo Nghiem") Exit Sub End If Else Console.WriteLine("Nghiem X= {0}", Math.Sqrt(-b / a)) End If End Sub Sub PTBac2(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) If a = 0 Then PTBac1(b, c) Else Dim Delta As Double = b * b - 4 * a * c If Delta < 0 Then Console.WriteLine("Phuong Trinh Vo Nghiem") ElseIf Delta = 0 Then Console.WriteLine("Phuong Trinh Co Nghiem Kep X= {0}", -b / 2 * a) Else Console.WriteLine("Phuong Trinh Co 2 Nghiem \nX1= {0} X2={1}", (-b + Math.Sqrt(Delta)) / 2 * a, (-b - Math.Sqrt(Delta)) / 2 * a) End If End If End Sub Sub PTBac4(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) If a = 0 Then PTBac2(b, 0, c) Else Dim Delta As Double = b * b - 4 * a * c If Delta < 0 Then Console.WriteLine("Phuong Trinh Vo Nghiem") ElseIf Delta = 0 Then Console.WriteLine("Phuong Trinh Co Nghiem Kep X= {0}", Math.Sqrt(-b / 2 * a)) Else Console.WriteLine("Phuong Trinh Co 2 Nghiem \nX1= {0} X2={1}", Math.Sqrt((-b + Math.Sqrt(Delta)) / 2 * a), Math.Sqrt((-b - Math.Sqrt(Delta)) / 2 * a)) End If End If End Sub Sub Main() Dim a, b, c As Integer Console.Write("Nhap Vao So a: ") a = Console.ReadLine() Console.Write("Nhap Vao So b: ") b = Console.ReadLine() Console.Write("Nhap Vao So c: ") c = Console.ReadLine() PTBac4(a, b, c) End Sub End Module |
Bài 67 TỔng Lũy thừa
| Code: |
Module Module1 Function TongLuyThua(ByVal x As Double, ByVal n As Integer) As Double Dim S As Integer = 0 Dim T As Integer = -1 Dim i As Integer For i = 1 To n Step 1 T = T * -x S = S + T Next Return S End Function Sub Main() Dim n As Integer Dim x As Double Dim kq As Double Console.Write("Nhap Vao So x: ") x = Console.ReadLine() Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TongLuyThua(x, n) Console.WriteLine("Ket Qua: {0}", kq) End Sub End Module |
Bài 68 TỔng Lũy thừa *
| Code: |
Module Module1 Function TongLuyThua(ByVal x As Double, ByVal n As Integer) As Double Dim S As Integer = 0 Dim T As Integer = 1 Dim i As Integer For i = 2 To 2 * n Step 2 T = T * -x * x S = S + T Next Return S End Function Sub Main() Dim n As Integer Dim x As Double Dim kq As Double Console.Write("Nhap Vao So x: ") x = Console.ReadLine() Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TongLuyThua(x, n) Console.WriteLine("Ket Qua: {0}", kq) End Sub End Module |
Bài 69 TỔng Lũy thừa **
| Code: |
Module Module1 Function TongLuyThua(ByVal x As Double, ByVal n As Integer) As Double Dim S As Integer = 0 Dim T As Integer = x Dim k = 1 Dim i As Integer For i = 1 To 2 * n Step 2 T = k * (x ^ i) S = S + T k = k * -1 Next Return S End Function Sub Main() Dim n As Integer Dim x As Double Dim kq As Double Console.Write("Nhap Vao So x: ") x = Console.ReadLine() Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TongLuyThua(x, n) Console.WriteLine("Ket Qua: {0}", kq) End Sub End Module |
Bài 70 TỔng Phân số
| Code: |
Module Module1 Function TongPhanSo(ByVal n As Integer) As Double Dim S As Double = 0 Dim T As Double = 0 Dim i As Integer For i = 1 To n Step 1 T = 1 / (T + i) S = S + T Next Return S End Function Sub Main() Dim n As Integer Dim kq As Double Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TongPhanSo(n) Console.WriteLine("Ket Qua: {0}", kq) End Sub End Module |
Bài 71
| Code: |
Module Module1 Function TongPhanSo(ByVal x As Integer, ByVal n As Integer) As Double Dim S As Double = 0 Dim T As Double = 1 Dim M As Integer = 0 Dim i As Integer For i = 1 To n Step 1 T = T * -x M = M + i S = S + T / M Next Return S End Function Sub Main() Dim n As Integer Dim x, kq As Double Console.Write("Nhap Vao So x: ") x = Console.ReadLine() Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TongPhanSo(x, n) Console.WriteLine("Ket Qua: {0}", kq) End Sub End Module |
Bài 72
| Code: |
Module Module1 Function TongPhanSo(ByVal x As Integer, ByVal n As Integer) As Double Dim S As Double = 0 Dim T As Double = 1 Dim M As Integer = 1 Dim i As Integer For i = 1 To n Step 1 T = T * -x M = M * i S = S + T / M Next Return S End Function Sub Main() Dim n As Integer Dim x, kq As Double Console.Write("Nhap Vao So x: ") x = Console.ReadLine() Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TongPhanSo(x, n) Console.WriteLine("Ket Qua: {0}", kq) End Sub End Module |
Bài 73
| Code: |
Module Module1 Function TongPhanSo(ByVal x As Integer, ByVal n As Integer) As Double Dim S As Double = -1 Dim T As Double = -1 Dim M As Integer = 1 Dim i As Integer For i = 2 To 2 * n Step 2 T = T * -x * x M = M * (i - 1) * i S = S + T / M Next Return S End Function Sub Main() Dim n As Integer Dim x, kq As Double Console.Write("Nhap Vao So x: ") x = Console.ReadLine() Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TongPhanSo(x, n) Console.WriteLine("Ket Qua: {0}", kq) End Sub End Module |
Bài 74
| Code: |
Module Module1 Function TongPhanSo(ByVal x As Integer, ByVal n As Integer) As Double Dim S As Double = 1 - x Dim T As Double = -x Dim M As Integer = 1 Dim i As Integer For i = 3 To 2 * n + 1 Step 2 T = T * -x * x M = M * (i - 1) * i S = S + T / M Next Return S End Function Sub Main() Dim n As Integer Dim x, kq As Double Console.Write("Nhap Vao So x: ") x = Console.ReadLine() Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = TongPhanSo(x, n) Console.WriteLine("Ket Qua: {0}", kq) End Sub End Module |
Bài 75
| Code: |
Module Module1 Function ChiaHet2MuK(ByVal n As Integer) As Integer Dim t As Integer If n = 1 Then Return 0 End If While n >= 2 t = n Mod 2 n = n \ 2 If t <> 0 Then Return 0 End If End While Return 1 End Function Sub Main() Dim n As Integer Dim kq As Double Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = ChiaHet2MuK(n) If kq = 1 Then Console.WriteLine("Chia Het Cho 2 ^ K") Else Console.WriteLine("Khong Chia Het Cho 2 ^ K") End If End Sub End Module |
Bài 76
| Code: |
Module Module1 Function ChiaHet3MuK(ByVal n As Integer) As Integer Dim t As Integer If n = 1 Or n = 2 Then Return 0 End If While n >= 3 t = n Mod 3 n = n \ 3 If t <> 0 Then Return 0 End If End While Return 1 End Function Sub Main() Dim n As Integer Dim kq As Double Console.Write("Nhap Vao So n: ") n = Console.ReadLine() kq = ChiaHet3MuK(n) If kq = 1 Then Console.WriteLine("Chia Het Cho 3 ^ K") Else Console.WriteLine("Khong Chia Het Cho 3 ^ K") End If End Sub End Module |
By 











0 nhận xét:
Post a Comment