Loop: GATE CS Previous Year Questions

Loop · Programming in C

17 questions · asked in 12 of 27 years (2000–2026)

MCQ 13 · MSQ 1 · NAT 31-mark 7 · 2-mark 10

2000Questions per year2026

Questions 11–15 of 17

Q11GATE 2014 (Session 1)2 marksMCQ−0.67 if wrong
Consider the following pseudo code. What is the total number of multiplications to be performed?
 D= 2
for i = 1 to n do
   for j = i to n do
      for k = j + 1 to n do
           D = D * 3 

Q12GATE 20061 markMCQ−0.33 if wrong
Consider the following C-function in which a[n] and b[m] are two sorted integer arrays and c[n+m] be another integer array.

void xyz (int a[],int b[],int c[]){
   int i, j, k;
   i=j=k=0;
   while((i < n) && (j < m))
            if (a[i] < b[j]) c[k++]=a[i++];
            else c[k++]=b[j++];
}
Which of the following condition(s) hold(s) after the termination of the while loop ?

I. j<\ltm, k=n+j-1, and a [n-1]<\ltb[j] if i=n
II. i<\ltn, k=m+i-1, and b[m-1]≤\leqa[i] if j=m

Q13GATE 20051 markMCQ−0.33 if wrong
Consider line number 3 of the following C-program.

int main ( ) { /* Line 1 */
int I, N; /* Line 2 */
fro (I =0, I < N, I++); /* Line 3 */
}
Identify the compiler's response about this line while creating the object-module:

Q14GATE 20041 markMCQ−0.33 if wrong
What does the following algorithm approximate? (Assume m>1,e>0m \gt 1, e \gt 0).
x = m;
y = 1;
while (x - y > e)
{
    x = (x + y)/2;
    y = m/x;
}
print(x); 

Q15GATE 20041 markMCQ−0.33 if wrong
Consider the following C program
main()
{
    int x, y, m, n;
    scanf ("%d %d", &x, &y);
    /* Assume x  >  0 and y  >  0  */
    m = x;
    n = y;
    while (m != n)
    {
        if (m  >  n)
            m = m - n;
        else
            n = n - m;
    }
    printf ("%d", n);
} 
The program computes

Keep practising

Topics in Programming in C

All CS topics ›