Professional Documents
Culture Documents
A. Excel Prediction. Determine the values at the specified cell after clicking the calculate button.
Sub Randomize()
Dim intX As Single
intX = CSng(Cells(2, 2).Value)
Dim intN As Integer
intN = CInt(Cells(3, 2).Value) Mod 4
Dim intResult As Integer
intResult = intX Mod 2
Dim sngArray() As Single
ReDim sngArray(intN)
Dim intCounter As Integer
If intResult = 0 Then
For intCounter = 0 To UBound(sngArray)
sngArray(intCounter) = Cells(intCounter + 6, intCounter + 1).Value
Next
Else
For intCounter = 0 To UBound(sngArray)
sngArray(intCounter) = Cells(intCounter + 6, 4 - intCounter).Value
Next
End If
Range("B11").Value =
Range("B12").Formula
Range("B13").Value =
Range("B14").Value =
sngArray(0) + intX
= "=SUM(A" & (6 + intN) & ":D" & (9 - intN) & ")"
sngArray(UBound(sngArray))
Cells(2, 2).Value + Cells(3, 2).Value
End Sub
Cell
Value
B2
B3
10
B11
(1)
11
(7)
B12
(2)
(4)
(8)
B13
(3)
(5)
(9)
B14
(6)
(10)
C. R Programming. Determine the value of x after each set of code. Take note that the following codes are continuous.
x<-0
vectA<seq(1,3,by=0.5)
for (counter in vectA)
{
x = x + counter
}
print(x)
1.
y<-x%%2 #mod operation
if(y==0){
while(y>-2){
x = x+1
y = y-1
}
} else {
while(y>-2){
x = x+1
y = y-1
}
}
print(x)
2.
x<-x+sum(vectA)
print(x)
3.
x<- 10. + 3. / 5. - x
print(x)
4.
x<-sum(c(TRUE,x,FALSE))
print(x)
5.