Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Module Module1
  2.     Function random(A As Integer, B As Integer) As Integer
  3.         random = Int(Rnd() * (B - A + 1) + A)
  4.     End Function
  5.  
  6.     Sub Main()
  7.         Call Randomize()
  8.         'Call randomValues()
  9.         'Call rectangle()
  10.         Call prob8()
  11.     End Sub
  12.  
  13.     Sub randomValues()
  14.         Dim r As Integer
  15.         Dim sum As Integer
  16.         sum = 0
  17.         Dim n As Integer
  18.         Console.Write("Put some number: ")
  19.         n = Console.ReadLine()
  20.         Dim num As Integer
  21.         num = 0
  22.         Dim max As Integer
  23.         max = 0
  24.         Do While sum <= n
  25.             r = random(0, 100)
  26.             Console.WriteLine("Random: " & r)
  27.             sum = sum + r
  28.             num = num + 1
  29.             If r > max Then
  30.                 max = r
  31.             End If
  32.         Loop
  33.         Console.WriteLine("Sum:    " & sum)
  34.         Console.WriteLine("Average:" & sum / num)
  35.         Console.WriteLine("Maximum:" & max)
  36.  
  37.     End Sub
  38.  
  39.     Sub passCheck()
  40.         Dim password As String
  41.         password = "Admin1234"
  42.         Dim userPass As String
  43.         Do
  44.             Console.Write("Enter password: ")
  45.             userPass = Console.ReadLine()
  46.         Loop While password <> userPass
  47.  
  48.         'If password = userPass Then
  49.         '    Console.WriteLine("Logged in")
  50.         'Else
  51.         '    Console.WriteLine("Wrong password")
  52.         'End If
  53.  
  54.     End Sub
  55.  
  56.     Sub prob2()
  57.         Dim number As Integer
  58.         number = 1
  59.         Dim max As Integer
  60.         number = InputBox("Give a number")
  61.         max = number
  62.         Do While number Mod 5 <> 0
  63.             number = InputBox("Give a number")
  64.             If max < number Then
  65.                 max = number
  66.             End If
  67.         Loop
  68.         Console.WriteLine("")
  69.         Console.WriteLine("max number = " & max)
  70.     End Sub
  71.  
  72.  
  73.  
  74.     Sub rectangle()
  75.         Dim w As Integer
  76.         Dim h As Integer
  77.         Console.Write("Height: ")
  78.         h = Console.ReadLine()
  79.         Console.Write("Width: ")
  80.         w = Console.ReadLine()
  81.  
  82.         Dim i As Integer
  83.         Dim j As Integer
  84.  
  85.         For j = 0 To h - 1
  86.             Console.Write("X")
  87.             For i = 0 To w - 3
  88.                 If j = h - 1 Or j = 0 Then
  89.                     Console.Write("X")
  90.                 Else
  91.                     Console.Write(" ")
  92.                 End If
  93.             Next i
  94.             Console.WriteLine("X")
  95.         Next j
  96.  
  97.     End Sub
  98.  
  99.     Sub prob4()
  100.         Dim r As Double
  101.         Do
  102.             r = InputBox("define radius")
  103.         Loop While r <= 0
  104.         Console.WriteLine("Area = " & Math.PI * r ^ 2)
  105.         Console.WriteLine("Circumference = " & 2 * Math.PI * r)
  106.     End Sub
  107.  
  108.     Sub prob5()
  109.         Dim a As Integer
  110.         Dim b As Integer
  111.         Dim decision As Integer
  112.         a = InputBox("First number")
  113.         b = InputBox("Second number")
  114.         decision = InputBox("Chose operation: 1-Sum, 2-Subtraction, 3-Multiplication, 4-Division, 5-Power, 6-Modulo")
  115.         If decision = 4 Or decision = 6 Then
  116.             Do While b = 0
  117.                 b = InputBox("b cannot be 0 for choosen operation. Define b again")
  118.             Loop
  119.         End If
  120.         If decision = 1 Then
  121.             MsgBox("Sum: " & (a + b))
  122.         ElseIf decision = 2 Then
  123.             MsgBox("Subtraction: " & (a - b))
  124.         ElseIf decision = 3 Then
  125.             MsgBox("Multiplication: " & (a * b))
  126.         ElseIf decision = 4 Then
  127.             MsgBox("Division: " & (a / b))
  128.         ElseIf decision = 5 Then
  129.             MsgBox("Power: " & (a ^ b))
  130.         ElseIf decision = 6 Then
  131.             MsgBox("Modulo: " & (a Mod b))
  132.         Else
  133.             MsgBox("ERROR - wrong operation number")
  134.         End If
  135.     End Sub
  136.  
  137.     Sub prob6()
  138.         Dim a As Integer
  139.         Dim b As Integer
  140.         Dim gcd As Integer
  141.         Do
  142.             a = InputBox("Define a")
  143.         Loop While a <= 0
  144.         Do
  145.             b = InputBox("Define b")
  146.         Loop While b <= 0
  147.  
  148.         Do While a <> b
  149.             If a > b Then
  150.                 a = a - b
  151.             Else
  152.                 b = b - a
  153.             End If
  154.         Loop
  155.         gcd = a
  156.         Console.Write("GCD = " & gcd)
  157.     End Sub
  158.  
  159.     Sub prob7()
  160.         Dim points As Double
  161.         Dim sum As Double
  162.         Dim g As Double
  163.         Do
  164.             Do
  165.  
  166.                 points = InputBox("Give number of points")
  167.                 If points < 0 Or points > 10 Then
  168.                     MsgBox("wrong number of points, it should be from interval [0,10]. Specify it again.")
  169.                 End If
  170.             Loop While points < 0 Or points > 10
  171.             sum = sum + points
  172.         Loop While sum <= 32
  173.         If sum < 16 Then
  174.             g = 2
  175.         ElseIf sum < 21 Then
  176.             g = 3
  177.         ElseIf sum < 25 Then
  178.             g = 3.5
  179.         ElseIf sum < 28 Then
  180.             g = 4
  181.         ElseIf sum < 31 Then
  182.             g = 4.5
  183.         Else
  184.             g = 5
  185.         End If
  186.         Console.WriteLine("Your grade is " & g)
  187.  
  188.     End Sub
  189.  
  190.     Sub prob8()
  191.         Dim e As Double
  192.         e = 1 * 10 ^ -10
  193.         Dim ai As Double
  194.         Dim s As Double
  195.         Dim q As Double
  196.         Dim i As Integer
  197.         q = 0.3
  198.  
  199.         Do
  200.             Console.WriteLine("Element i = " & i & " equals = " & ai)
  201.             ai = q ^ i
  202.             s = s + ai
  203.             i = i + 1
  204.         Loop While Math.Abs(ai) >= e
  205.         Console.WriteLine("")
  206.         Console.WriteLine("Sum of S " & s)
  207.         Console.WriteLine("Analitycal sum of S " & 1 / (1 - q))
  208.         Console.WriteLine("Error " & 1 / (1 - q) - s)
  209.  
  210.         'recursive version:
  211.         Console.WriteLine("Recursive version:")
  212.         i = 1
  213.         ai = 1
  214.         s = 1
  215.         Do
  216.             Console.WriteLine("Element i = " & i & " equals = " & ai)
  217.             ai = ai * q
  218.             s = s + ai
  219.             i = i + 1
  220.         Loop While Math.Abs(ai) >= e
  221.         Console.WriteLine("")
  222.         Console.WriteLine("Sum of S " & s)
  223.         Console.WriteLine("Analitycal sum of S " & 1 / (1 - q))
  224.         Console.WriteLine("Error " & 1 / (1 - q) - s)
  225.  
  226.  
  227.     End Sub
  228. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement