编写一简单程序,计算S=A+B+C

编写一简单程序,计算S=A+B+C,第1张

用什么写啊?

这样的程序,几乎太多的东西要以实现了!!!!

以c 为例:

#include <stdio.h>

main()

{

int S,A,B,C

printf("输入A,B,C的值:\n")

scanf("%d%d%d",&A,&B,&C)

S=A+B+C

printf("S=%d",S)

}

sub实现:

Private Sub Command1_Click()

Dim a As Long, b As Long, c As Long

a = Val(InputBox("请输入一个大于0的整数A:"))

b = Val(InputBox("请输入一个大于0的整数B:"))

c = Val(InputBox("请输入一个大于0的整数C:"))

If a >0 And b >0 And c >0 Then

n1 a

n1 b

n1 c

MsgBox "A!+B!+C!=" &a + b + c

End If

End Sub

Sub n1(n As Long)

Dim i As Long, s As Long

s = 1

For i = 2 To n

s = s * i

Next

n = s

End Sub

function实现:

Private Sub Command1_Click()

Dim a As Long, b As Long, c As Long

a = Val(InputBox("请输入一个大于0的整数A:"))

b = Val(InputBox("请输入一个大于0的整数B:"))

c = Val(InputBox("请输入一个大于0的整数C:"))

If a >0 And b >0 And c >0 Then

MsgBox "A!+B!+C!=" &n2(a) + n2(b) + n2(c)

End If

End Sub

Function n2(n As Long) As Long

Dim i As Long

n2 = 1

For i = 2 To n

n2 = n2 * i

Next

End Function

请注意:输入的数字不能太大,因为受Long型最大值的限制,计算13!即溢出。要想计算更大的数值,可使用Double数值类型

我试过了,肯定能运行出来

Private Sub Form_Click()

Dim a, b, c, s, sa, sb, sc, i As Integer

sa = 1

sb = 1

sc = 1

a = InputBox("请输入a的值")

For i = 1 To a

sa = sa * (Val(a))

Next i

b = InputBox("请输入b的值")

For i = 1 To b

sb = sb * (Val(b))

Next i

c = InputBox("请输入c的值")

For i = 1 To c

sc = sc * (Val(c))

Next i

s = sa + sb + sc

Print s

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11068859.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存