Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Function random(A As Integer, B As Integer) As Integer
- random = Int(Rnd() * (B - A + 1) + A)
- End Function
- Sub Main()
- Call Randomize()
- 'Call randomValues()
- 'Call rectangle()
- Call prob8()
- End Sub
- Sub randomValues()
- Dim r As Integer
- Dim sum As Integer
- sum = 0
- Dim n As Integer
- Console.Write("Put some number: ")
- n = Console.ReadLine()
- Dim num As Integer
- num = 0
- Dim max As Integer
- max = 0
- Do While sum <= n
- r = random(0, 100)
- Console.WriteLine("Random: " & r)
- sum = sum + r
- num = num + 1
- If r > max Then
- max = r
- End If
- Loop
- Console.WriteLine("Sum: " & sum)
- Console.WriteLine("Average:" & sum / num)
- Console.WriteLine("Maximum:" & max)
- End Sub
- Sub passCheck()
- Dim password As String
- password = "Admin1234"
- Dim userPass As String
- Do
- Console.Write("Enter password: ")
- userPass = Console.ReadLine()
- Loop While password <> userPass
- 'If password = userPass Then
- ' Console.WriteLine("Logged in")
- 'Else
- ' Console.WriteLine("Wrong password")
- 'End If
- End Sub
- Sub prob2()
- Dim number As Integer
- number = 1
- Dim max As Integer
- number = InputBox("Give a number")
- max = number
- Do While number Mod 5 <> 0
- number = InputBox("Give a number")
- If max < number Then
- max = number
- End If
- Loop
- Console.WriteLine("")
- Console.WriteLine("max number = " & max)
- End Sub
- Sub rectangle()
- Dim w As Integer
- Dim h As Integer
- Console.Write("Height: ")
- h = Console.ReadLine()
- Console.Write("Width: ")
- w = Console.ReadLine()
- Dim i As Integer
- Dim j As Integer
- For j = 0 To h - 1
- Console.Write("X")
- For i = 0 To w - 3
- If j = h - 1 Or j = 0 Then
- Console.Write("X")
- Else
- Console.Write(" ")
- End If
- Next i
- Console.WriteLine("X")
- Next j
- End Sub
- Sub prob4()
- Dim r As Double
- Do
- r = InputBox("define radius")
- Loop While r <= 0
- Console.WriteLine("Area = " & Math.PI * r ^ 2)
- Console.WriteLine("Circumference = " & 2 * Math.PI * r)
- End Sub
- Sub prob5()
- Dim a As Integer
- Dim b As Integer
- Dim decision As Integer
- a = InputBox("First number")
- b = InputBox("Second number")
- decision = InputBox("Chose operation: 1-Sum, 2-Subtraction, 3-Multiplication, 4-Division, 5-Power, 6-Modulo")
- If decision = 4 Or decision = 6 Then
- Do While b = 0
- b = InputBox("b cannot be 0 for choosen operation. Define b again")
- Loop
- End If
- If decision = 1 Then
- MsgBox("Sum: " & (a + b))
- ElseIf decision = 2 Then
- MsgBox("Subtraction: " & (a - b))
- ElseIf decision = 3 Then
- MsgBox("Multiplication: " & (a * b))
- ElseIf decision = 4 Then
- MsgBox("Division: " & (a / b))
- ElseIf decision = 5 Then
- MsgBox("Power: " & (a ^ b))
- ElseIf decision = 6 Then
- MsgBox("Modulo: " & (a Mod b))
- Else
- MsgBox("ERROR - wrong operation number")
- End If
- End Sub
- Sub prob6()
- Dim a As Integer
- Dim b As Integer
- Dim gcd As Integer
- Do
- a = InputBox("Define a")
- Loop While a <= 0
- Do
- b = InputBox("Define b")
- Loop While b <= 0
- Do While a <> b
- If a > b Then
- a = a - b
- Else
- b = b - a
- End If
- Loop
- gcd = a
- Console.Write("GCD = " & gcd)
- End Sub
- Sub prob7()
- Dim points As Double
- Dim sum As Double
- Dim g As Double
- Do
- Do
- points = InputBox("Give number of points")
- If points < 0 Or points > 10 Then
- MsgBox("wrong number of points, it should be from interval [0,10]. Specify it again.")
- End If
- Loop While points < 0 Or points > 10
- sum = sum + points
- Loop While sum <= 32
- If sum < 16 Then
- g = 2
- ElseIf sum < 21 Then
- g = 3
- ElseIf sum < 25 Then
- g = 3.5
- ElseIf sum < 28 Then
- g = 4
- ElseIf sum < 31 Then
- g = 4.5
- Else
- g = 5
- End If
- Console.WriteLine("Your grade is " & g)
- End Sub
- Sub prob8()
- Dim e As Double
- e = 1 * 10 ^ -10
- Dim ai As Double
- Dim s As Double
- Dim q As Double
- Dim i As Integer
- q = 0.3
- Do
- Console.WriteLine("Element i = " & i & " equals = " & ai)
- ai = q ^ i
- s = s + ai
- i = i + 1
- Loop While Math.Abs(ai) >= e
- Console.WriteLine("")
- Console.WriteLine("Sum of S " & s)
- Console.WriteLine("Analitycal sum of S " & 1 / (1 - q))
- Console.WriteLine("Error " & 1 / (1 - q) - s)
- 'recursive version:
- Console.WriteLine("Recursive version:")
- i = 1
- ai = 1
- s = 1
- Do
- Console.WriteLine("Element i = " & i & " equals = " & ai)
- ai = ai * q
- s = s + ai
- i = i + 1
- Loop While Math.Abs(ai) >= e
- Console.WriteLine("")
- Console.WriteLine("Sum of S " & s)
- Console.WriteLine("Analitycal sum of S " & 1 / (1 - q))
- Console.WriteLine("Error " & 1 / (1 - q) - s)
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement