Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Basic程序设计1-10 | 罗中算法练习 #2

Open
AltureT opened this issue Jan 30, 2019 · 13 comments
Open

Visual Basic程序设计1-10 | 罗中算法练习 #2

AltureT opened this issue Jan 30, 2019 · 13 comments

Comments

@AltureT
Copy link
Owner

AltureT commented Jan 30, 2019

https://alturet.github.io/lifenote/2019/01/22/VisualBasica/

Visual Basic程序设计1-10题目1:输入三个整数x,y,z,请把这三个数由小到大输出。样例输入(3个Text文本框输入):

@AltureT
Copy link
Owner Author

AltureT commented Jan 30, 2019

关于github账号注册,同学们可以百度搜索:github注册

@wbenteng
Copy link

题目一的另一种解法倪

@AltureT
Copy link
Owner Author

AltureT commented Jan 30, 2019

@wbenteng
题目一的另一种解法倪

等你在评论里写出来,哈哈

@wbenteng
Copy link

这。。。我写写看,有点忘了

@wbenteng
Copy link

Private Sub Command1_Click()
Dim a(1 To 3) As Integer
a1 = Val(Text1.Text): a2 = Val(Text2.Text): a3 = Val(Text3.Text)
For i = 1 To 2
For j = i + 1 To 3
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
Label1.Caption = Str(a1) + "" + Str(a2) + "" + Str(a3)

End Sub

@AltureT
Copy link
Owner Author

AltureT commented Jan 30, 2019

@wbenteng
Private Sub Command1_Click()
Dim a(1 To 3) As Integer
a1 = Val(Text1.Text): a2 = Val(Text2.Text): a3 = Val(Text3.Text)
For i = 1 To 2
For j = i + 1 To 3
If a(i) > a(j) Then
t = a(i): a(i) = a(j): a(j) = t
End If
Next j
Next i
Label1.Caption = Str(a1) + "" + Str(a2) + "" + Str(a3)

End Sub

排序代码没错,可是你有两个小问题:

  1. 你定义的是数组变量a,写法应该是a(1),而不是a1
  2. 输出这里
Label1.Caption = Str(a1) + "" + Str(a2) + "" + Str(a3)

a1改成a(1),然后你加了一个""字符串,不是相当于没加吗.
不过str函数默认会在前面加一个空格的

@wbenteng
Copy link

那你答案的输出语句的“”“”也可以去掉哩

@AltureT
Copy link
Owner Author

AltureT commented Jan 30, 2019

@wbenteng
那你答案的输出语句的“”“”也可以去掉哩

恩,是的,可是我写出来是一种提示作用,有些学生可能不清楚str用完后会自动在前面加一个空格

@wbenteng
Copy link

第二题的sum用integer会不会溢出呀

@AltureT
Copy link
Owner Author

AltureT commented Jan 30, 2019

@wbenteng
第二题的sum用integer会不会溢出呀

你说的对,我只限制了单个数,两数加起来就超过integer范围了,我稍后修改

@AltureT
Copy link
Owner Author

AltureT commented Feb 6, 2019

@yichengsjw123
题目七的另一种解法
Dim a , b , c as Integer
Dim s as Integer
a=Val (text1.text)
b=Val (text2.text)
c=Val (text3.text)
If a>b then t=a:a=b:b=t
If a>c then t=a:a=c:c=t
If b>c then t=b:b=c:c=t
s=b+c
Lable1.caption= Str( s)

很不错的思路,先将3个数字从小到大排序,然后将最大的两个相加。

另外提醒一点,我们在评论中添加代码,可以代码上方加入(双引号里面的部分)“ ```vb ”,下方加入“ ``` ”,让我们的代码更加美观:

Dim a , b , c as Integer
Dim s as Integer
a=Val (text1.text)
b=Val (text2.text)
c=Val (text3.text)
If a>b then t=a:a=b:b=t
If a>c then t=a:a=c:c=t
If b>c then t=b:b=c:c=t
s=b+c
Lable1.caption= Str(s)

@AltureT
Copy link
Owner Author

AltureT commented Feb 6, 2019

写完后可以点击预览观察效果,格式如下图:
添加代码

@LuisGarrettLyu
Copy link

你好,黄老师
网站做的真不错!继续努力!
祝顺利

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@AltureT @wbenteng @LuisGarrettLyu and others