Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub do1()
- Dim bot As Integer, user As Integer, c As Integer
- bot = CInt(Rnd * 10)
- c = 0
- Do
- user = InputBox("Zgadnij liczbe:")
- If (user > bot) Then
- MsgBox "Za dużo"
- ElseIf (user < bot) Then
- MsgBox "Za mało"
- End If
- c = c + 1
- Loop Until user = bot
- MsgBox "Liczba prawidłowa, zgadłeś za " & c & " razem"
- End Sub
- Sub do2()
- Dim i As Integer, sum As Integer, a As Integer
- i = 1
- a = 5
- sum = 0
- Do
- Cells(i, 1) = a
- sum = sum + a
- i = i + 1
- a = a + 1
- Loop Until sum > 100
- End Sub
- Sub do3()
- Dim a As Integer, i As Integer
- a = 3
- i = 1
- Do
- If (a Mod 3 = 0 Or a Mod 5 = 0) Then
- Cells(i, 1) = a
- i = i + 1
- End If
- a = a + 1
- Loop While i <= 15
- End Sub
- Sub do4()
- Dim i As Integer, x As Single, Xk As Single, P As Single, Rok As Integer
- x = InputBox("Podaj kapitał początkowy")
- P = InputBox("Podaj oprocentownie")
- i = 1
- Xk = 0
- Do
- Xk = x * (1 + P / 100) ^ i
- i = i + 1
- Loop Until Xk >= 2 * x
- MsgBox i - 1
- End Sub
- Sub do5a()
- Dim dec As Integer, bin As Integer, i As Integer
- dec = InputBox("Podaj liczbe dziesiętną, zakres 0 do 255", "Zamiana liczby dzisiętnej na 8-bitową binarną")
- i = 0
- If dec >= 0 And dec <= 255 Then
- Do
- bin = dec Mod 2
- dec = dec \ 2
- Cells(2, 8 - i) = bin
- If Cells(2, i + 1) = "" Then
- Cells(2, i + 1) = 0
- End If
- i = i + 1
- Loop Until dec = 0
- Else
- MsgBox "Liczba nie mieści się w podanym zakresie"
- End If
- End Sub
- ' StrReverse(string) odwaraca ciąg
- Sub do5b()
- Dim dec As Integer, bin As Integer, i As Integer, wynik As String, x As Integer
- dec = InputBox("Podaj liczbę dziesiętną do konwersji na postać binarną") ' liczba dziesiętna znajduje się w komórce A1
- x = dec ' kopiuję wartość dec
- Do Until dec = 0
- bin = dec Mod 2
- dec = dec \ 2
- wynik = wynik & bin
- Loop
- MsgBox "Liczba " & x & " binarnie to:" & Chr(13) & StrReverse(wynik)
- End Sub
- Sub do6()
- Dim x As Integer, tmp As Integer, i As Integer
- x = InputBox("Podaj liczbę")
- tmp = 1
- i = 0
- Do
- tmp = tmp * 2
- i = i + 1
- Loop While tmp < x
- If tmp = x Then
- MsgBox "Liczbę " & x & " można przedstawić jako 2^" & i
- Else
- MsgBox "Liczby " & x & " nie można przedstawić jako 2^n"
- End If
- End Sub
- Sub do7()
- Dim a As Integer, b As Integer, r As Integer, NWD As Integer
- a = InputBox("Podaj a:")
- b = InputBox("Podaj b:")
- Do
- r = a Mod b
- If r = 0 Then
- NWD = b
- Else
- a = b
- b = r
- End If
- Loop Until r = 0
- MsgBox NWD
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement