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 16–17 of 17

Q16GATE 20041 markMCQ−0.33 if wrong
Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n=d1d2...dmn=d_{1}d_{2}...d_{m}.
int n, rev;
rev = 0;
while (n  >  0)
{
   rev = rev*10 + n%10;
   n = n/10;
} 
The loop invariant condition at the end of the ithi^{th} iteration is:

Q17GATE 20031 markMCQ−0.33 if wrong
Consider the following C function.

float f(float x, int y)
{
  float p, s; int i;
  for (s=1, p=1, i=1; i < y; i ++)
  {
    p*= x/i;
    s+=p;
  }
  return s;
}  
For large values of y, the return value of the function f best approximates

Keep practising

Topics in Programming in C

All CS topics ›