Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

virtual, prolog, критерий, uses, procedure, game, row, обзоры, unit, сборник, граф, record, ряд, tree, byte, прототипирование, type, record, basic, const, logic
 

for valuable work you must have JavaScript (allow active content)

Visual Basic. B.13. Nest of tasks. Functions

 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.1     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr1(n As Integer) As Integer
    Pr1 = n * (n - 1)
End Function

Function Pr2(k As Integer, n As Integer) As Integer
    Pr2 = k * k - n * n
End Function

Function AA() As Integer
Dim i As Integer
    s = 0
    For i = 1 To 2
        s = s + Pr1(Pr2(i + 1, i))
    Next i
    AA = s
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.2     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr1(n As Integer) As Integer
    Pr1 = n + 1
End Function

Function AA() As Integer
Dim i As Integer
Dim s As Integer
    s = 1
    For i = 1 To 4
        s = Pr1(s)
    Next i
    AA = s
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.3     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr(n As Integer) As Integer
    s = 0
    For i = 1 To n
        s = s + i
    Next i
    Pr = s
End Function

Function AA() As Integer
Dim j As Integer
Dim m As Integer
    m = 1
    For j = 1 To 3
        m = m * Pr(j)
    Next j
    AA = m
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.4     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr1(n As Integer, k As Integer) As boolean
    Pr1 = Not (n * k > k \ 2)
End Function

Function AA() As Integer
Dim j As Integer
Dim m As Integer
    s = 0
    If Pr1(3, 4) Then
        s = 15
    Else
        For j = 1 To 3
            s = s + j
        Next j
    End If
    AA = s
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.5     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr1(n As Integer) As Integer
    Pr1 = n \ 2
End Function

Function Pr2(n As Integer) As Integer
    Pr2 = n * n
End Function

Function Pr3(n As Integer) As Integer
    Pr3 = n Mod 2
End Function

Function AA() As Integer
Dim i As Integer
Dim s As Integer
    s = 0
    For i = Pr1(3) To Pr2(3)
        s = s + Pr3(i)
    Next i
    AA = s
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.6     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr1(n As Integer) As Integer
    Pr1 = n \ 2
End Function

Function Pr2(n As Integer) As Integer
    Pr2 = n * n
End Function

Function Pr3(n As Integer) As Integer
    Pr3 = n Mod 2
End Function

Function AA() As Integer
Dim i As Integer
Dim j As Integer
Dim s As Integer
    s = 0
    For i = 1 To 2
        For j = Pr1(i) To Pr2(i)
            s = s + Pr3(j)
        Next j
    Next i
    AA = s
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.7     Answer      Pascal-analogue

Determine a value produced by function AA .


Function Pr(n As Integer) As Boolean
    m = 0
    For j = 1 To n
        m = m + j
    Next j
    Pr = (m Mod n = 0)
End Function

Function AA() As Integer
Dim k As Integer
Dim s As Integer
    s = 0
    k = 3
    Do
        s = s + k
        k = k + 1
    Loop Until Pr(k)
    AA = s
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.8     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function A1(N As Integer) As Integer
    A1 = N * N
End Function

Function A2(N As Integer) As Integer
    A2 = A1(N) + 2
End Function

Function A3(N As Integer) As Integer
    A3 = A1(N) * 3
End Function

Function AA() As Integer
Dim k As Integer
Dim m As Integer
    XX = 0
    For k = 1 To 2
        For m = A2(k) To A3(k)
            XX = XX + 1
        Next m
    Next k
    AA = XX
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.9     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr1(n As Integer) As Integer
    Pr1 = n * (n - 1)
End Function

Function Pr2(k, n As Integer) As Integer
    Pr2 = k * k - n * n
End Function

Function AA() As Integer
    s = 0
    For i = 1 To 2
        s = s + Pr1(Pr2(i + 1, i - 1))
    Next i
    AA = s
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.10     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr1(n As Integer) As Integer
    Pr1 = n * 3 + 1
End Function

Function AA() As Integer
Dim s As Integer
    s = 1
    For i = 1 To 4
        s = Pr1(s)
    Next i
    AA = s
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.11     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr1(n, k As Integer) As Boolean
    Pr1 = ((n + k + 2) > ((k * 5) \ 3))
End Function

Function AA() As Integer
Dim s As Integer
    s = 0
    If Pr1(3, 4) Then
        s = s + 2
    End If
    If Pr1(3, 2) Then
        s = s + 3
    End If
    If Pr1(4, 6) Then
        s = s + 7
    End If
    If Pr1(5, 1) Then
        s = s + 11
    End If
    If Pr1(0, 2) Then
        s = s + 20
    End If
    AA = s
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.12     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr1(n As Integer) As Integer
    Pr1 = n \ 2
End Function

Function Pr2(n As Integer) As Integer
    Pr2 = n * n
End Function

Function Pr3(n As Integer) As Integer
    Pr3 = n Mod 2
End Function

Function AA() As Integer
Dim s As Integer
Dim i As Integer
    s = 0
    For i = Pr1(3) To 3
        s = s + Pr1(Pr2(Pr3(i)))
    Next i
    AA = s
End Function


 

 

Calculator

/ - division

\ - rest

S - sum of numbers from and to

P - multiply numbers from and to

B.13.13     Answer      Pascal-analogue      Java-analogue

Determine a value produced by function AA .


Function Pr1(n As Integer) As Integer
    Pr1 = n + 2
End Function

Function Pr2(n As Integer) As Integer
    Pr2 = n * n + 5
End Function

Function Pr3(n As Integer) As Integer
    Pr3 = n * 2
End Function

Function AA() As Integer
Dim s As Integer
Dim i As Integer, j As Integer
    s = 0
    For i = 1 To 2
        For j = Pr1(i) To Pr2(i)
            s = s + Pr3(j)
        Next j
    Next i
    AA = s
End Function



 

©   Aliaksandr Prykhodzka    1993 - 2007