Questions on C++, I am not 100% sure on answers, so need to clarify. Simple explanation next to the question would be nice as well.
In mathematic notation, which is equivalent to the following statement when writing a
pseudocode?
x = 4y
A. x == 4y
B. x := 4y
C. x -> 4y
D. 4y = x
Start
int x = 5;
for i in 1 to 3 do
x = x + i
End
A. 5
B. 7
C. 9
D. 11
E. 13
r←m%n
while r !=0 do
m←n
n←r
r←m%n
return n
A. 3
B. 12
C. 6
D. 15
E. 8
for (int i=1; i<17; i++)
{
cout << (5 / i) * 3;
}
A. 17
B. 18
C. 34
D. 36
int findRemainder(int x, int y)
{
int r = x % y;
return r;
}
A. constant
B. linear
C. quadratic
D. exponential
E. logarithmic
int x = 3;
int y = 4;
for i = 1 to n do
x = x + i
y = y - i
print x
print y
A. 2n
B. 4n + 2
C. 6n + 4
D. 8n + 6
E. 5n + 6
Q1 Ans) B
In pseudocode format, you can use = or := for
assignment operation.
Here in Given Options.
A) x == 4y ; == is used for
equality checking.
B) x:= 4y ; := is an assignment
operation(correct)
C) x-> 4y ; -> denotes
Replaced by
D) 4y = x ; 4y is assigned to x
Q2 Ans) D
Initially x is assigned to 5
for i = 1 => x = x + 1 ; x= 5 + 1 = 6
i = 2 => x = x + 2 ; x= 6 + 2 = 8
i = 3 => x = x + 3 ; x= 8 + 3 = 11
Q3 Ans)A
Initially, r = 24 % 3 = 0
Since r == 0 it doesn’t enter into loop and returns
simply n value. i.e,, 3
Q4 Ans) None of Them.
The loop executes for i=1 to i=16 only. Since i<17
doesn’t iterate for i=17. The answer is 16.
Q5 Ans) A
It just requires constant amount i.e,, O(1) time
complexity as it just calculates the remainder.
int findRemainder(int x, int y)
{
int r = x % y; -> O(1)
return r; -> O(1)
}
Q6 Ans) A
The total number of statements are 2 and The loop
executes for n times.
So, it executes 2n times.
Get Answers For Free
Most questions answered within 1 hours.