教材习题及答案 联系客服

发布时间 : 星期六 文章教材习题及答案更新完毕开始阅读f3615d5e76c66137ee0619e6

0 (x<=0) y = f(x) = 4x/3 (015)

3. 设x1=0133表示火车1点33分开出,x2=2209表示火车22点09分到站。x1和x2都是

整数,计算火车运行的时间y(运行时间假设小于24小时),同样用一个4位整数表示,前2位为小时数,后两位是分钟数。

4. 计算序列2/1+3/2+5/3+8/5+...的前n项之和。

5. 给定一个含有10个整数的数组,判断x是否在数组中。如是,将x在数组中的位置(下

标)存于变量y中。否则y的值为-1。 6. 将第2题以过程调用的方式实现。过程如

Function WaterFee (ByVal x As Deciaml) As Decimal 7. 将第5题以过程的方式实现,如:

Function IsHere (ByVal A() As Integer, ByVal x As Integer) As Integer

8. 某公司员工的工资计算方法如下,一周内工作时间40小时之内(含40小时),按正常

工作时间计酬,超出40小时的工作时间部分,按正常工作时间报酬的1.5倍计酬。员工按进公司时间分为新职工和老职工,新职工的正常工资为30/小时,老职工的正常工资为50/小时。(进公司5年以上(含5年)的员工为老职工,5年以下的为新职工), 请按该计酬方式计算员工的工资。要求输入员工进公司的一周工作时间、工作年数,输出其一周的工资,保留2位小数。

9. 输入年份、月份、日子,输出这一天是该年中的第几天。如输入3个整数,2009 3 2,

则输出This is the 61th of 2009。 10. 一只猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个;第二天早

上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第n天(1

如何搭配(输出所有可能的配对情况)? 12. 打印输出所有“水仙花数”。所谓“水仙花数”是指一个三位的正整数,其各位数字立

方和等于该数本身。例如:153是一个“水仙花数”,因为153=13+53+33。 13. 编写过程IsSquare,判断某个自然数是否为平方数。是返回True,不是则返回False。 14. 求数组中出现次数最多的数及出现次数。数组为整数,8个数。输出出现最多的数以及

次数。 15. 一个自然数是素数,且它的各位数字位置经过任意对换后仍为素数,则称是绝对素数。

例如13是绝对素数。输出所有2位数的绝对素数。

第5章习题答案

‘—1--

Module Module1

Sub Main()

Console.WriteLine(\请输入3个整数,以空格分隔并以回车结束\ Dim s As String = Console.ReadLine() Dim sSplit() As String = s.Split(\

Dim x, y, z As Integer

x = Convert.ToInt32(sSplit(0)) y = Convert.ToInt32(sSplit(1)) z = Convert.ToInt32(sSplit(2))

Console.WriteLine(\ Console.WriteLine(\ End Sub

End Module

‘—2—

Module Module1

Sub Main()

Dim A() As Single = {12, 30} Dim y As Single For Each x In A If x <= 0 Then y = 0 Else

If x > 0 And x <= 15 Then y = 4 * x / 3 Else

y = 2.5 * x - 10.5 End If End If

Console.WriteLine(\ Next End Sub

End Module

‘—3—‘

Module Module1

Sub Main()

Dim x1 As Integer = 133 Dim x2 As Integer = 2209 Dim x1h As Integer = x1 \\ 100 Dim x1m As Integer = x1 Mod 100 Dim x2h As Integer = x2 \\ 100 Dim x2m As Integer = x2 Mod 100 Dim yh, ym As Integer

If x2m - x1m < 0 Then ym = x2m + 60 - x1m yh = x2h - x1h - 1 Else

ym = x2m - x1m yh = x2h - x1h End If

If yh < 0 Then yh = yh + 24 End If

Dim y As Integer = yh * 100 + ym Console.WriteLine(\

End Sub

End Module

‘—4—

Module Module1

Sub Main()

Const n As Integer = 30 Dim a As Integer = 2 Dim b As Integer = 1 Dim sum As Decimal = 0 For i As Integer = 1 To n sum = sum + a / b Dim t As Integer = a a = a + b b = t Next

Console.WriteLine(\ End Sub

End Module

‘—5—

Module Module1

Sub Main()

Dim A() As Integer = {23, 34, 56, 78, 12, 2, 45, 6, 7, 90} Dim x As Integer = 56 Dim y As Integer = -1

For i As Integer = 0 To A.Length - 1 If x = A(i) Then y = i End If Next

Console.WriteLine(\ End Sub

End Module

‘—6—

Module Module1

Sub Main()

Dim A() As Single = {12, 30} For Each x In A

Console.WriteLine(\ Next

End Sub

Function WaterFee(ByVal x As Decimal) As Decimal If x <= 0 Then Return 0 Else

If x > 0 And x <= 15 Then Return 4 * x / 3 Else

Return 2.5 * x - 10.5 End If End If End Function

End Module