You are on page 1of 4

Quiz 11 - Section 1 #0000002538 | On May 4, 2017 15:48

Administrator Remarks Processing

StudentID

Email
Which array will be the
output when the code
below is excuted?
i <- 1
rand.vec <-
vector()

repeat {
rand.num <-
rnorm(1)
if(rand.num > 0)
{
rand.vec<-
c(rand.vec,rand.num
)
i <- i + 1
}
if(i ==
101){break}
}

par(mfcol = c(2,2))
plot(rand.vec)
hist(rand.vec)
par(mfrow = c(1,1))
What is the output of the
following code? [1] 2
i <- 0 [1] 4
j <- 1 [1] 6
vector <- [1] 8
c(1,2,1,2,1,2,1,2,1
)
while(j<=9) { [1] 3
i <- i + [1] 6
vector[j] * [1] 9
vector[j+1] [1] 12
j <- j+1
print(i) [1] 2
if(j == 5) { [1] 4
break [1] 6
} [1] 8
next [1] 10
print(j)
}
[1] 3
[1] 2
[1] 6
[1] 3
[1] 9
[1] 4
[1] 12

What is the output of the


code below? [,1] [,2] [,3]
matrix_creator <- [1,] 2 3 4
function(row, [2,] 3 4 5
column) { [3,] 4 5 6
A <-
matrix(nrow=row,
ncol=column) [,1] [,2] [,3]
[1,] 0 -1 -2
for (i in [2,] 1 0 -1
1:nrow(A)){ [3,] 2 1 0
for (j in
1:ncol(A)){ [,1] [,2] [,3]
A[i,j] <- i+j [1,] 1 1 1
} [2,] 2 2 2
} [3,] 3 3 3
return(A)
}
[,1] [,2] [,3]
matrix_creator(3,3) [1,] 1 2 3
[2,] 2 4 6
[3,] 3 6 9

Which one of the Repeat loops are used whenever we don?t have a condition to test.
followings is correct?
You can use break for 'for loops'.

For loops uses more CPU time.

It is impossible to obtain endless while loops.


What is the output of the
following code? [1] 1
a <- 5 [1] 1
number <- 3 [1] 1
vec1 <- [1] 1
seq(3,15,by=3) [1] 1
while(a>=1) {
number <-
((vec1[a]/3)/a) [1] 3
print(number) [1] 5
a <- a-1 [1] 4
} [1] 3
[1] 2
[1] 1

[1] 5
[1] 4
[1] 3
[1] 2
[1] 1

[1] 3
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5

You might also like