ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:17.54KB ,
资源ID:27827534      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/27827534.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(VB常见常用的编程题代码.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

VB常见常用的编程题代码.docx

1、VB常见常用的编程题代码常见常用的程序代码输入n个整数求最大值 Sub Main() Console.WriteLine(输入n个整数) Dim s As String = Console.ReadLine() Dim A() As String = s.Split( ) Dim aa(A.Length - 1) As Integer For i As Integer = 0 To A.Length - 1 aa(i) = Convert.ToInt32(A(i) Next Dim max As Integer = aa(0) For i As Integer = 1 To aa.Length

2、 - 1 If aa(i) max Then max = aa(i) End If Next Console.WriteLine(最大数为0, max) End Sub 输出n之间的素数 Sub main() Dim n As Integer = Convert.ToInt32(Console.ReadLine() If n 2 Then Console.WriteLine(输入错误) End If For i As Integer = 2 To n If isprime(i) Then Console.Write(i) Console.Write( ) End If Next Console

3、.WriteLine() End Sub Function isprime(ByVal n As Integer) As Boolean If n = 2 Then Return True Else Dim i As Integer = 2 While i = n / i If n Mod i = 0 Then Return False End If i = i + 1 End While Return True End If End Function 3.字符串也有求长度和按 (i) 输出的功能 Sub Main() Dim expression As String Console.Writ

4、eLine(输入一个字符串) expression = Console.ReadLine For i As Integer = 0 To expression.Length - 1 Console.Write(expression(i) Console.Write( ) Next End Sub 4.输入年月日输出这是该年中的第几天 闰年的条件:能被4整除但不能被100整除或能被400整除Sub main() Dim a() As Integer = 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 Dim b() As Integer = 31,

5、29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 Console.WriteLine(输入年月日) Dim m As String = Console.ReadLine() Dim msplit() As String = m.Split(,) Dim n, month, data As Integer Dim sum As Integer = 0 n = Convert.ToInt32(msplit(0) month = Convert.ToInt32(msplit(1) data = Convert.ToInt32(msplit(2) If n = 1

6、Then sum = data End If If (n Mod 4 = 0) And (n Mod 100 0) Or (n Mod 400 = 0) Then For i As Integer = 0 To month - 2 sum = sum + b(i) Next Else : For i As Integer = 0 To month - 2 sum = sum + a(i) Next End If sum = sum + data Console.Write(sum) End Sub 线性表和栈.队列题型1. 电话号码本Structure people Dim name As S

7、tring Dim number As Integer End Structure Structure listtype Dim data() As people Dim n As Integer End StructureSub Main() Dim list As listtype Dim max As Integer = 1000 ReDim list.data(max) Dim p1, p2, p3 As people p1.name = haha p1.number = 23456Sub insert(ByRef l As listtype, ByVal i As Integer,

8、ByVal x As people) If i = 0 And i i l.data(j) = l.data(j - 1) j = j - 1 End While l.data(i) = x l.n = l.n + 1 Else : Console.WriteLine(位置不正确) End IfEnd Sub Sub delete(ByRef l As listtype, ByVal i As Integer) If i = 0 And i l.n Then While i l.n l.data(i) = l.data(i + 1) i = i + 1 End While l.n = l.n

9、- 1 Else : Console.WriteLine(位置不正确) End If End Sub Sub print(ByRef l As listtype) For i As Integer = 0 To l.n - 1 Console.WriteLine(l.data(i).name) Console.WriteLine(l.data(i).number) Next End Sub 2.检查括号是否匹配 a.用new stcak 实现 Sub Main() Dim expression As String Console.WriteLine(输入一个字符串) expression =

10、Console.ReadLine() Dim s As New Stack(Of String) s.Clear() Dim ch As String For i As Integer = 0 To expression.Length - 1 ch = expression(i) If ch = ( Then s.Push(ch) End If If ch = ) Then If s.Count 0 Then Console.WriteLine(不匹配) Else: s.Pop() End If End If End if If s.Count = 0 Then Console.WriteLi

11、ne(匹配) Else Console.WriteLine(不匹配) End If End Sub B.用数组实现 Structure stack Dim ch() As String Dim top As Integer Dim bottom As Integer End Structure Sub Main() Dim examp As stack Dim max As Integer = 10000 ReDim examp.ch(max) Console.WriteLine(输入字符串) Dim expression As String = Console.ReadLine() For

12、i As Integer = 0 To expression.Length - 1 If expression(i) = ( Then push(examp, expression(i) End If If expression(i) = ) Then If examp.top s.bottom Then s.top = s.top - 1 Return s.ch(s.top) Else : Return vbNull End IfEnd Function 3.将一组字符串进行反序 Sub Main() Console.WriteLine(输入字符串) Dim expression As St

13、ring = Console.ReadLine Dim exam As New Stack(Of String) exam.Clear() Dim ch As String For i As Integer = 0 To expression.Length - 1 ch = expression(i) exam.Push(ch) Next While exam.Count 0 Console.Write(exam.Pop() End While End Sub 判断是否为回文序列Sub Main() Console.WriteLine(输入字符串) Dim expression As Stri

14、ng = Console.ReadLine() Dim exam1 As New Stack(Of String) Dim exam2 As New Stack(Of String) exam1.Clear() exam2.Clear() Dim ch As String For i As Integer = 0 To expression.Length - 1 ch = expression(i) exam1.Push(ch) ch = expression(expression.Length - 1 - i) exam2.Push(ch) Next Dim flag As Boolean

15、= True For i As Integer = 0 To expression.Length - 1 If exam1.Pop() exam2.Pop() Then flag = False Exit For End If Next If flag = True Then Console.WriteLine(y) Else : Console.WriteLine(n) End If End Sub 5. 折半查找Sub Main() Dim a() As Integer = 1, 2, 3, 4, 5, 6, 7, 8 Dim k = binsearch(a, 4) If k = 0 Th

16、en Console.WriteLine( 查找的数据在数组中的位置为: + k.ToString() Else Console.WriteLine( 数据没有找到) End If End Sub Function binsearch(ByVal a() As Integer, ByVal key As Integer) As Integer Dim low As Integer = 0 Dim high As Integer = a.Length - 1 While low = high Dim mid As Integer = (low + high) / 2 If key = a(mid

17、) Then Return mid If key = 0 Then Console.WriteLine(查找的位置在0, k) Else : Console.WriteLine(不存在) End If End Sub Function search(ByVal s() As Integer, ByVal key As Integer) As Integer For i As Integer = 0 To s.Length - 1 If s(i) = key Then Return i End If Next Return -1End Function 7.冒泡排序 Sub Main() Dim

18、 s() As Integer = 1, 2, 3, 4, 5, 6, 7 show(s) bubble(s) show(s) End Sub Sub show(ByVal s() As Integer) For Each k As Integer In s Console.Write(k.ToString() + ) Next End Sub Sub bubble(ByVal s() As Integer) Dim lenghth As Integer = s.Length For i As Integer = 0 To lenghth - 1 For j As Integer = leng

19、hth - 1 To i + 1 Step -1 If s(j) s(j - 1) Then Dim temp As Integer = s(j) s(j) = s(j - 1) s(j - 1) = temp End If Next Next End Sub 8.选择排序 Sub Main() Dim s() As Integer = 2, 9, 7, 5 show(s) Console.WriteLine(排序结果是) Selectsort(s) show(s) End Sub Sub show(ByVal s() As Integer) For Each k As Integer In

20、s Console.Write(k.ToString() + ) Next End Sub Sub selectsort(ByVal s() As Integer) Dim lenghth As Integer = s.Length For i As Integer = 0 To lenghth - 2 For j As Integer = i + 1 To lenghth - 1 If s(j) s(i) Then Dim temp As Integer = s(j) s(j) = s(i) s(i) = temp End If冒泡排序Dim lenghth As Integer = s.L

21、engthFor i As Integer = 0 To lenghth - 1 For j As Integer = lenghth - 1 To i + 1 Step -1 If s(j) s(j - 1) Then Dim temp As Integer = s(j) s(j) = s(j - 1) s(j - 1) = temp End If Next Next快速排序Dim lenghth As Integer = s.Length For i As Integer = 0 To lenghth - 2 For j As Integer = i + 1 To lenghth - 1 If s(j) s(i) Then Dim temp As Integer = s(j) s(j) = s(i) s(i) = temp End If Next

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1