用InputBox函数输入10个数与数组A中,输入后将这10个数显示在文本框中,并统计正数的个数,正数的和,负数

用InputBox函数输入10个数与数组A中,输入后将这10个数显示在文本框中,并统计正数的个数,正数的和,负数的个数,负数的和。用Print方法将结果打印在窗体上,设计界面、运行结果如图所示。

Option Explicit

Private Sub Form_Click()

Dim i As Integer, s(9) As Integer

Dim a1 As Integer, a2 As Integer

Dim b1 As Integer, b2 As Integer

For i = 0 To 9

s(i) = InputBox("请输入", "提示")

Text1.Text = Text1.Text + Str(s(i)) + Chr(9)

If s(i) > 0 Then

a1 = a1 + 1

a2 = a2 + s(i)

ElseIf s(i) < 0 Then

b1 = b1 + 1

b2 = b2 + s(i)

End If

Next i

Scale (-10, 10)-(10, -10)

CurrentX = -7.5

CurrentY = 0

Print "正数的个数="; a1; "正数的和="; a2

CurrentX = -7.5

Print "正数的个数="; b1; "正数的和="; b2

End Sub

扩展资料:

注意事项

一、占位符不要乱用,要选择正确的对应类型,否则可能会损失精度。

二、C没有String类型,C的字符串实际就是字符数组。

三、C数组定义,[ ]只能再变量名之后。

四、 C字符串两种定义方式。

五、char str[] = {'h','e','l','l','o','\0'};//注意'\0'字符串结束符。

六、char str[] = "你好"; //这种定义方式不用写结束符 可以表示汉字。

七、函数不可以定义为数组,可以用函数指针来操作。

函数指针的数组定义方法:返回值类型( * 指针变量名[Number]) (形参列表)。例如:

double add(double a,double b){}

double sub(double a,double b){}

double mul(double a,double b){}

double div1(double a,double b){}

double (*oper_func[])(double, double) = {add,sub,mul,div1};//函数指针的数组定义。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-07
Private Sub Command1_Click()
Dim a(9) As Integer
For i = 0 To 9
a(i) = InputBox("请输入一个整数", "请输入")
Next i
s1 = 0
s2 = 0
c1 = 0
c2 = 0
For i = 0 To 9
If a(i) > 0 Then
s1 = s1 + a(i)
c1 = c1 + 1
Else
s2 = s2 + a(i)
c2 = c2 + 1
End If
Text1.Text = Text1.Text & a(i) & " "
Next i
Me.Print "正整数的个数等于:" & c1 & " "; "正整数的和等于:" & s1
Me.Print "负整数的个数等于:" & c2 & " "; "负整数的和等于:" & s2
End Sub
第2个回答  推荐于2018-02-28
Private Sub form_load()
Dim i As Integer, zs As Integer
Dim zsum As Single, fsum As Single
Dim A(1 To 10) As Single
Me.AutoRedraw = True
Text1 = ""
For i = 1 To 10
A(i) = Val(InputBox("输入第" & i & " 个数"))
If A(i) >= 0 Then
zs = zs + 1: zsum = zsum + A(i)
Else
fsum = fsum + A(i)
End If
Text1 = Text1.Text & Space(5) & A(i)
Next i
Me.CurrentY = Text1.Top + Text1.Height
Print
Print "正数的个数= " & zs & " 正数的和= " & zsum
Print "负数的个数= " & 10 - zs & " 负数的和= " & fsum
End Sub本回答被提问者和网友采纳
第3个回答  2011-12-07
Dim x As Integer, y As Integer
For i = 1 To 10
A(i) = InputBox(("输入第" & i & " 个数"))
Text1.Text = Text1.Text & A(i) & " "
Next i
For i = 1 To 10
If A(i) > 10 Then m = m + 1: x = x + A(i)
If A(i) < 0 Then n = n + 1: x = x + A(i)
Next i
Label1.Caption = Str(m)
Label2.Caption = Str(x)
Label1.Caption = Str(n)
Label1.Caption = Str(y)
End Sub
一些控件就自己安排吧
第4个回答  2011-12-07
Option Explicit

Private Sub Form_Click()
Dim i As Integer, s(9) As Integer
Dim a1 As Integer, a2 As Integer
Dim b1 As Integer, b2 As Integer
For i = 0 To 9
s(i) = InputBox("请输入", "提示")
Text1.Text = Text1.Text + Str(s(i)) + Chr(9)
If s(i) > 0 Then
a1 = a1 + 1
a2 = a2 + s(i)
ElseIf s(i) < 0 Then
b1 = b1 + 1
b2 = b2 + s(i)
End If
Next i
Scale (-10, 10)-(10, -10)
CurrentX = -7.5
CurrentY = 0
Print "正数的个数="; a1; "正数的和="; a2
CurrentX = -7.5
Print "正数的个数="; b1; "正数的和="; b2
End Sub

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网