好文档 - 专业文书写作范文服务资料分享网站

数字处理程序

天下 分享 时间: 加入收藏 我要投稿 点赞

8. 验证下列命题:设n是一个s1是n的各位数字之和,s2是2n的各位数字之和。若s1=s2,则n是9的倍数。根据图

2和程序填写对象的相关属性,

\代表该对象无属性。

对象窗体标签文本框判断按钮退出按钮

Private Sub CmdVerify_Click()

名称(Name)

Frm1 LblInput TxtInput (CmdVerify)CmdExit

标题(Caption)

(验证命题)(输入一个两位数)

X 验证退出

正文(Text)

X X 空X X

Dim n As Integer,s1 As Integer,sa As Integer n=Val__(TxtInput_) s1=Sm(n) s2=Sm(2*n)

If ___(s1=s2 and n Mod 9=0MsgBox \该命题成立\Else

MsgBox \该命题不成立\End If

TxtInput.Text=\TxtInput.SetFocus End Sub

Private Sub CmdExit_Click() Unload Me End Sub

Private Function Sm(___Dim sm1 as integer sm1=0 Do While n<>0 sm1=sm1+n Mod 10

(ByVal n As Integer

)___) As Integer

)___Then

___(n=n\\10)___ Loop Sm=sm1 End Function

8. 下面程序的功能是验证回文数猜想。

任取一自然数,将其倒过来,并将这两个数相加,

后把这个和数倒过来,与原来的和数相加……重复这个过程有限次,必将得到一个回文数。所谓回文数指左右数字完全对称的自然数,例如,猜想,假如取一自然数回文数1111。Option Explicit

Private Sub Form_Click()

Dim S As Long,D As Long,Sum As Long Dim Flg As Boolean

S=InputBox(\输入一个正整数\Do D=Fun(S) Sum =S+D

Print Sum;\Call Comp(Sum,Flg) S=___(Sum)___ Loop Until Flg Print Sum;\End Sub

Private Function Fun(N As Long)As Long Dim Char As String,J As Long Dim I As Integer,Slen As Integer Char=Ltrim(Str(N)) ___(Slen=Len(Char))___ J=1

For I=1 To Slen

Fun=Fun+Val(Mid(Char,I,1))*J ___(J=J*10或J=10^i)___ Next I End Function

Private Sub Comp(N As Long,F As Boolean) Dim Ch As String,S As Integer,I As Integer S=Len(Ltrim(Str(N)))

是回文数\

6868+86=154

121,12321,898,111均是回文数。根据

605+506=1111,经过三步运算就得到

154+451=605

F=False Ch=Ltrim(Str(N)) For I=1 To___(S)___

If Mid(Ch,I,1)<>Mid(CH,S+1-I,1)Then Exit Sub

Next I

___(F=True)___ End Sub

9.下面程序的功能是从键盘上输入一个不超过4位的十进制正整数,先把该十进数的每一位

数字转换位一个4位二进制数,再把得到的二进制数依次合并成为一个

16位的二进制数。如输入十进制数

359,会得到二进制数

0000001101011001。

Private Sub Form_Click()

Dim num As Integer, s As String, M As Integer Dim i As Integer, j As Integer, n As Integer num = InputBox(\输入一个长度不超过

4位的十进制正整数:

\

___M=num__ Do While num>0 j=j + 1 n=num Mod 10 s=cover(n) & s ___num=num\\10__ Loop For i=1 To 4-j s=\Next i Text1.Text=\十进制数\的转换结果是:\

End Sub

Private Function cover(ByVal n As Integer)As String Dim i As Integer, s As String, k As Integer Do Until n<1 ___k=n Mod 2__ s=CStr(k) & s n=n\\2 Loop

If Len(s)< 4 Then s=\cover=__right(s,4)__Else cover=s End If

End Function

7.下面程序的功能是将以“

12;3;15”形式输入的字符串分解为数字

2为本程序执行画面)。

12、3、15,分

别赋给3个数组元素,并对其进行简单运算(图

Private Sub Command1_Click()

Dim a(3)As Integer, i As Integer, n As Integer Dim s As String s = Text1.Text For i = 1 To 2

n = InStr(s, \

a(i)= Left(s, n - 1)s = Mid(s, n + 1, Len(s) - n)Next i

A(3)= Val( s )

Text2.Text = a(1)* a(2)+ a(3)End Sub

图2

8.本程序是找零巧数。所谓零巧数是具有下述特性的四位正整数:其百位数为去掉0,得到一个三位正整数,是零巧数(如图

3所示)。

而该正整数乘以

0,如果

9,等于原数。例如2025=225×9,所以2025

图3

Private Function Change(s As String)As String Dim p As String, i As Integer For i = 1 To Len(s)If i <> 2 Then End If Next i

'是否为左边第二位数

'将每位字符串连接

p = p + Mid(s, i, 1)

Change = p End Function

Private Sub Command1_Click()Dim i As Integer, s As String For i = 1000 To 9999

s = CStr(i)

'在四位数之间查找'将数值转变成字符串

'取百位数,并判断是否为

\

9后是否等于原来的数

If Mid(s, 2, 1)= \

If Val(Change(s))* 9 = i Then '去掉百位数后的数乘

List1.AddItem CStr(i)+ \(s)+ \

'连接成字符串后,添加到列表框内

End If End If Next i End Sub

9.本程序是把给定的二进制整数转换为八进制整数。Private Sub Command1_Click()Dim a As String, b As String, c As String a = InputBox(\请输入一个二进制数L = 3 -(Len(a))Mod 3a = String(L, \)& a n = Len(a)/ 3 For m = 1 To n

b = Mid(a, 3 * m - 2, 3)c = c + zh(b)Next m Text1.Text = c End Sub

Private Function zh(s As String)As String

Dim i As Integer, n As Integer, p As Integer p = 1

For i = 2 To 0 Step -1

n = n * 2 + Val(Mid(s, p, 1))p = p + 1 Next i zh = Str(n)End Function

10.找出由两个不同数字组成的平方数,并将结果按图中。

Option Explicit

\输入框\)

4中的格式显示在列表框List1

数字处理程序

8.验证下列命题:设n是一个s1是n的各位数字之和,s2是2n的各位数字之和。若s1=s2,则n是9的倍数。根据图2和程序填写对象的相关属性,\代表该对象无属性。对象窗体标签文本框判断按钮退出按钮PrivateSubCmdVerify_Click()名称(Name)Frm1LblInputTxtI
推荐度:
点击下载文档文档为doc格式
22cfr8x6c14ncj33s2bw8iiwn4795r0188y
领取福利

微信扫码领取福利

微信扫码分享