Page 268 - Computer science 868 Class 12
P. 268

21.  The following is a function of some class that sorts an integer array a[] in ascending order using the selection sort technique.
                    There are some places in the code marked by ?1?, ?2?, ?3?, ?4?, ?5? which may be replaced by some statements/expressions so
                    that the function works properly.
                    void selectsort(int []a)
                    {
                    int i, j, t, min, minpos;
                    for(i=0;i {
                    min=a[i];
                    minpos = i;
                    for(j=?2?;y<a.length;j++) { if(min>a[j])
                    {
                    ?3?=j;
                    min = ?4?;
                    }
                    }
                    t=a[minpos];
                    a[minpos]=a[i];
                    a[i]= ?5?;
                    }
                    for(int k=0;k<a.length;k++)
                    System. out.println(a[k]);
                    }
                    (i)  What is the expression or statement at ?1?
                    (ii)   What is the expression or statement at ?2?
                   (iii)  What is the expression or statement at ?3?
                   (iv)  What is the expression or statement at ?4?
                    (v)  What is the expression or statement at ?5?
                 22.  The following function Check() is a part of some class. What will the function Check() return when the values of both ‘m’ and ‘n’
                    are equal to 5? Show the dry run/working.
                    int Check (int m, int n)
                     {
                       if(n == 1)
                           return - m--;
                       else
                           return ++m + Check (m, --n);
                   }
                 23.  The following function is a part of some class that computes and returns the greatest common divisor of any two numbers. There
                    are some places in the code marked by ?1?, ?2?, ?3?, ?4? and ?5? which must be replaced by some statements/expressions so
                    that the function works correctly.
                    int gcd(int a, int b)
                    {
                    int r;
                    while(?1?)
                    {
                    r = ?2?;
                    b = ?3?;
                    a = ?4?
                    }
                    if (a ==0)
                    return ?5?;
                    else




                266266  Touchpad Computer Science-XII
   263   264   265   266   267   268   269   270   271   272   273