Question 21
EasyWhat is the output of this pseudocode?
Integer m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, s = 0
for (each i from 0 to 2)
s = s + m[i][i]
end for
Print s
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Pseudocode and Output Prediction
What is the output of this pseudocode?
Integer m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, s = 0
for (each i from 0 to 2)
s = s + m[i][i]
end for
Print s
12
45
24
15
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer a[] = {1, 2, 2, 3, 3, 3}, count = 0
for (each i from 1 to 5)
if (a[i] == a[i - 1])
count = count + 1
end if
end for
Print count
6
2
5
3
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer a[] = {4, 6, 7, 2}, found = -1
for (each i from 0 to 3)
if (a[i] == 7)
found = i
end if
end for
Print found
7
-1
3
2
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer a[] = {12, 5, 20, 9}
Integer mx = a[0], mn = a[0]
for (each i from 1 to 3)
if (a[i] > mx)
mx = a[i]
end if
if (a[i] < mn)
mn = a[i]
end if
end for
Print mx - mn
25
8
7
15
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer a[] = {2, 4, 6}
for (each i from 0 to 2)
a[i] = a[i] * a[i]
end for
Print a[2]
12
36
16
6
Sign up free to see the answer and a step-by-step explanation.
What does the following pseudocode print?
Integer a[] = {9, 8, 7, 6, 5, 4}
Integer n = 6
Print a[n - 1]
9
6
4
5
Sign up free to see the answer and a step-by-step explanation.
What will be printed by the following pseudocode?
Integer a[] = {10, 1, 20, 2, 30, 3}, s = 0
for (each i from 1 to 5 step 2)
s = s + a[i]
end for
Print s
66
33
60
6
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer a[] = {1, 2, 3, 4, 5}
for (each i from 0 to 1)
Integer t = a[i]
a[i] = a[4 - i]
a[4 - i] = t
end for
Print a[0], a[1], a[2], a[3], a[4]
5 2 3 4 1
2 1 3 5 4
5 4 3 2 1
1 2 3 4 5
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer a[] = {1, 2, 3, 4, 5}
Integer t = a[0]
for (each i from 0 to 3)
a[i] = a[i + 1]
end for
a[4] = t
Print a[0], a[4]
5 1
1 5
2 1
2 5
Sign up free to see the answer and a step-by-step explanation.
What will be the output of the following pseudocode?
Integer a[] = {4, 1, 3, 2}
for (each i from 0 to 2)
for (each j from 0 to 2 - i)
if (a[j] > a[j + 1])
swap(a[j], a[j + 1])
end if
end for
end for
Print a[0], a[1], a[2], a[3]
1 3 2 4
4 3 2 1
2 1 3 4
1 2 3 4
Sign up free to see the answer and a step-by-step explanation.