当前位置:编程学习 > VB >>

VB编程题。

爱因斯坦走台阶:有一台阶,如果每次走两阶,最后剩一阶;如果每次走三阶,最后剩两阶;如果每次走四阶,最后剩三阶;如果每次走五阶,最后剩四阶;如果每次走六阶,最后剩五阶;如果每次走七阶,刚好走完.求此第三小的台阶数是多少?

补充:这个题目有答案了,谢谢你的回答。可以帮我做下这个改错题目吗?

程序功能:求三位偶数中,个位数字与十位数字之和除以10所得的余数是百位数字的数的个数。程序中有两行有错误。改正错误,使它能输出正确的结果。

Private Sub Command1_Click()

Dim count As Integer

Dim a As Integer, b As Integer, c As Integer

Dim x As Integer

count = 0 :x = 100

 While x <= 999

 a = Int(x / 100): b = Int(x / 10) - a * 10: c = x - a * 100 - b * 10

if mod(x,2)=0 OR mod(b+c,10)=a then

count = count + 1

End If

x = x + 1

 Loop

Print count

End Sub

 

答案:楼主追加的问题里答案是29。我的代码如下:

Private Sub Command1_Click()
c = 0
For n = 100 To 998 Step 2
If (n Mod 10) + (n - (n Mod 10)) / 10 Mod 10 = (n - (n Mod 100)) / 100 Then c = c + 1
Next n
Print c
End Sub

 

楼主的代码里错误很多~~~

Private Sub Command1_Click()

Dim count As Integer

Dim a As Integer, b As Integer, c As Integer

Dim x As Integer

count = 0 :x = 100

 While x <= 999  '----------------------这里While 要改用 “do While” ,没有do是不符合语法的。

 a = Int(x / 100): b = Int(x / 10) - a * 10: c = x - a * 100 - b * 10

if mod(x,2)=0 OR mod(b+c,10)=a then  '-----------------除非是前面有自定义函数,否则mod(x,2)=0不合法,应该是 “x mod 2=0”,而mod(b+c,10)=a问题同前,且这里不能用“or”,因为两个条件要同时满足,所以应改为“and”。

count = count + 1

End If

x = x + 1

 Loop

Print count

End Sub

 

这两处的代码改完以后,答案就是29了。

Option Explicit
Private Sub Form_Click()
    Dim n As Long, m As Long
    Do Until m = 3
        Do
            n = n + 1
            If n Mod 2 = 1 And n Mod 3 = 2 And n Mod 4 = 3 And n Mod 5 = 4 And n Mod 6 = 5 And n Mod 7 = 0 Then Exit Do
        Loop
        m = m + 1
    Loop
    MsgBox "第三小的台阶数:" & n
End Sub

上一个:VB编程问题
下一个:计算机VB编程

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,