GATE 2004 Computer Science and Information Technology (CS) Questions with Solutions

GATE 2004

199 questions

MCQ 1991-mark 199

Questions 86–90 of 199

Q86Loop1 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); 

Q87Loop1 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

Q88Loop1 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:

Q89Function1 markMCQ−0.33 if wrong
Consider the following C program:
#include <stdio.h>
typedef struct {
    char *a;
    char *b;
    } t;
void f1 (t s);
void f2 (t *p);
main()
{
    static t s = {"A", "B"};
    printf ("%s %s\n", s.a, s.b);
    f1(s);
    printf ("%s %s\n", s.a, s.b);
    f2(&s);
}
void f1 (t s)
{
    s.a = "U";
    s.b = "V";
    printf ("%s %s\n", s.a, s.b);
    return;
}
void f2(t *p)
{
    p -> a  = "V";
    p -> b = "W";
    printf("%s %s\n", p -> a, p -> b);
    return;
}
What is the output generated by the program ?

Q90Function1 markMCQ−0.33 if wrong
Choose the correct option to fill the ?1 and ?2 so that the program prints an input string in reverse order. Assume that the input string is terminated by a new line character.
#include <stdio.h>
void wrt_it (void);
int main (void)
{
    printf("Enter Text"); 
    printf ("\n");
    wrt_it();
    printf ("\n");
    return 0;
}
void wrt_it (void)
{
    int c;
    if (?1)
        wrt_it();
    ?2
}