Question 7832 – GATE 2018
December 23, 2023
Question 14317 – Computer-Networks
December 23, 2023
Question 7832 – GATE 2018
December 23, 2023
Question 14317 – Computer-Networks
December 23, 2023

Question 14209 – GATE 2021 CS-Set-1

Consider the following ANSI C function:
int SimpleFunction (int Y[], int n, int x)
{
     int total = Y[0], loopIndex;
     for (loopIndex = 1; loopIndex <= n – 1; loopIndex++)
                   total = x * total + Y[loopIndex]
     return total;
}
Let Z be an array of 10 elements with Z[i]=1, for all i such that 0 ≤ i ≤ 9. The value returned by SimpleFunction(Z, 10, 2) is _______

Correct Answer: A

Question 11 Explanation: 
Array Z consists of 10 elements and that element’s values are 1.
n=10,x=2
Initial total value is 1 => total=1.
For loop will execute 9 times.
loopindex=1, 1<=9 condition is true then
total = x * total + Y[loopIndex]= 2*1+Y[1]=2+1=3
loopindex=2, 2<=9 condition is true then
total=2*3+Y[2]=6+1=7
loopindex=3, 3<=9 condition is true then
total=2*7+Y[3]=14+1 =15
loopindex=4, 4<=9 condition is true then
total= 2*15+Y[4]=30+1=31
loopindex=5, 5<=9 condition is true then
total=2*31+Y[5]=62+1=63
loopindex=6, 6<=9 condition is true then
total=2*63+Y[6]=126+1=127
loopindex=7, 7<=9 condition is true then
Total =2*127+Y[7]=254+1=255
loopindex=8, 8<=9 condition is true then
total=2*255+Y[8]=510+1=511
loopindex=9, 9<=9 condition is true then
total=2*511+Y[9]=1022+1=1023
loopindex=10, 10<=9 condition is false then
Total value is returned which is 1023.
You can also write generalized formulae 210-1=1023
A
1023
3 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!