'--------------------------------------------------------------------- ' 問題1 '--------------------------------------------------------------------- Sub 問題1() Dim m As Integer Dim n As Integer m = InputBox("mを入力") n = InputBox("nを入力") If [ 1 ] Then MsgBox "少なくてもnとmのどちらかは奇数" Else MsgBox "nとmはどちらも偶数か奇数" End If End Sub '--------------------------------------------------------------------- ' 問題2 '--------------------------------------------------------------------- Sub 問題2() Dim n As Integer Dim ryokin As Integer Dim kingaku As Integer m = InputBox("mを入力") n = InputBox("nを入力") If [ 1 ] Then MsgBox "m と n はともに偶数" ElseIf [ 2 ] Then MsgBox "m は奇数で n は偶数" ElseIf [ 3 ] Then MsgBox "m は偶数で n は奇数" Else MsgBox "m と n はともに奇数数" End If End Sub '--------------------------------------------------------------------- ' 問題3 '--------------------------------------------------------------------- Sub 問題3() Dim i As Integer Dim j As Integer Dim count As Integer Dim sosu As Integer Dim l As Integer Dim u As Integer Dim max As Integer Randomize l = Int(20 * Rnd + 1) u = Int(100 * Rnd + 1) max = [ 1 ] For j = [ 2 ] count = 0 For i = 1 To j If [ 3 ] Then count = count + 1 End If Next i If count = 2 Then sosu = [ 4 ] End If If [ 5 ] Then max = sosu End If Next j MsgBox "範囲:[" & l & "," & u & "] " & "最大値=" & max End Sub '--------------------------------------------------------------------- ' 問題4 '--------------------------------------------------------------------- Sub 問題4() Dim x As Integer Dim y As Integer Dim z As Integer Dim yakusu As Integer Dim baisu As Long Randomize x = Int(10 * Rnd + 1) y = Int(20 * Rnd + 1) z = Int(30 * Rnd + 1) For i = 1 To x If [ 1 ] Then yakusu = i End If Next i MsgBox "(" & x & "," & y & "," & z & ")" & vbCrLf & "最大公約数=" & yakusu End Sub '--------------------------------------------------------------------- ' 問題5 '--------------------------------------------------------------------- Sub 問題5() Dim i As Integer Dim j As Integer Dim n As Integer Dim count As Integer Dim sum As Integer sum = 0 j = 2 Do While [ 1 ] count = 0 For i = 1 To j If j Mod i = 0 Then count = count + 1 End If Next i If count = 2 Then sum = [ 2 ] n = [ 3 ] End If j = [ 4 ] Loop MsgBox "n=" & n & "合計=" & sum End Sub