...个控制台应用程序用来从键盘上输入两个数然后输出这两个数的和差积...

发布网友 发布时间:2024-10-24 02:17

我来回答

2个回答

热心网友 时间:2024-10-26 09:42

应该定义为double或者single,string类好像不能进行运算。我简单说一下控制台的方法,你要一次性输入和差积商,首先声明两个变量用来储存两个数,然后用算法一次性输出结果就ok。

Sub Main()
Dim FN As Single
Dim SN As Single
Dim ResultNum As Single
Console.WriteLine("请输入第一个数") : FN = Console.ReadLine
Console.WriteLine("请输入第二个数") : SN = Console.ReadLine
ResultNum = FN + SN
Console.WriteLine("它们的和: " & ResultNum)
ResultNum = FN - SN
Console.WriteLine("它们的差: " & ResultNum)
ResultNum = FN * SN
Console.WriteLine("它们的积: " & ResultNum)
ResultNum = FN / SN
Console.WriteLine("它们的商: " & ResultNum)
Console.ReadLine()
End Sub

热心网友 时间:2024-10-26 09:37

Module Module1
Sub Main()
Dim FN As Decimal
Dim SN As Decimal
Dim sum As Decimal
Dim dec1 As Decimal
Dim dec2 As Decimal
Dim dec3 As Decimal
Try
Console.WriteLine("请输入第一个数:")
FN = Decimal.Parse(Console.ReadLine)
Console.WriteLine("请输入第二个数:")
SN = Decimal.Parse(Console.ReadLine)
sum = FN + SN
dec1 = FN - SN
dec2 = FN * SN
dec3 = FN / SN
Console.WriteLine("和:{0},差:{1},积:{2},商:{3}", sum, dec1, dec2, dec3)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.WriteLine("按任意键退出")
Console.ReadKey()
End Sub
End Module
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com