1.期中考

'5,10

'1.印出 2A+B

'2.印出最大值

'3.印出數列 5,6,7,8,9,10

'4.印出偶數數列 6,8,10

'5.印出偶數數列的和 24

Dim a, b As Integer

a = Console.ReadLine

b = Console.ReadLine

Console.WriteLine("1.2A+B=" & 2 * a + b)

If a > b Then

Console.WriteLine("2.最大值 = " & a)

Else 'b>a

Console.WriteLine("2.最大值 = " & b)

End If

'3-------------------------

Console.Write("3.印出數列 ")

For i = a To b 'for i = 5 to 10

Console.Write(i)

Console.Write(",")

Next

'4-------------------------

Console.WriteLine("") '換行

Console.Write("4.印出偶數數列 ")

For i = a To b 'for i = 5 to 10

If i Mod 2 = 0 Then '判斷是否為偶數

Console.Write(i)

Console.Write(",")

End If

Next

'5-------------------------

Dim sum As Integer

sum = 0

Console.WriteLine("") '換行

Console.Write("5.印出偶數數列的和 ")

For i = a To b 'for i = 5 to 10

If i Mod 2 = 0 Then '判斷是否為偶數

sum = sum + i

End If

Next

Console.Write(sum)

Console.ReadKey()