PREVIOUS QUESTIONS: SET-1

SET-1         SET-2       SET-3      SET-4       Coding  MCQs


SET-1       

Question 1:
In c language, if a function return type is not explicitly defined then it defaults to what data type?


Answer: Int
Question 2:
Which of the following syntax is correct for command -line arguments?
a. int main (char *argv[], int argc)
b. none of the three options
c. int main ()
{
int argv, char *argc[];
}
d. int main(int var, char *varg[])


Answer: d
Question 3:
Which of the below is NOT a data type in C language:
a.    Signed int
b.    Big int
c.    Short int
d.    Long int

Answer: b) Big int
Question 4:
The pseudo code below sorts an array using bubble sort. Here A is the array and the” n” is the number of element in it. Function swap exchanges the value of 2 given value.
1.    Function bubbleSort(A,n)
2.    {
3.    For i =0 to n-2  step 1
4.    For j = 0 to n-1-2 step 1
5.    if( A (j) > A(j+1))
6.    Swap(A(j),A(j+1))
7.    }
This function is called with A and 7 as parameter where the array a initially contains the element 64, 34,  25,12, 22, 11, 9. Then which of the following is correct after executing the above algorithm for 2 iterations.
a.    34 25 12 22 11 9 64
b.    25 12 22 11 9 34 64
c.    11 9 12 22 25 34 64
d.    12 11 9 22 25 34 64

Answer: b) 25 12 22 11 9 34 64
Question 5:
realloc () function is used to:
a. Get back the memory that was released earlier using dree() funcion
b. Reallocate a file pointer when switching between files
c. Change the size of an array
d. Change the size of dynamically allocated memory

Answer: d) change the size of dynamically allocated memory
Question 6:
The full set of operations allowed on a stack are
a. Push ,pop
b. Push,pop,remove
c. Push,pop, add,remove
d. Push,pop,add,remove,substitute

Answer: a) push,pop
Question 7:
Eesha wants to implement an image viewer application to view images in a given folder. The application will be able to display an image and will also know what its next and previous images are at any given point of time so that the user can so that the user can view next/previous image by pressing right/left keys on the keyboard. Which data structure is appropriate for Esha to use?
1.    Tree
2.    Queue
3.    Linked list
4.    Stack

Answer: Linked list
Question 8:
Advanced The figure depicts a search space in which the nodes are labelled with names like A,B,A1,B1. Node S is the start node. The goal are drawn as square boxes and the other noted in circle Enter answer as a sequence of node separated by a comma, please DO NOT enter any blanks anywhare in the response
For example, If the answer (order of nodes) is a followed by c, followed by A1, followed by D, the answer should be A,C,A1,D
Starting with the node start  node,list the order in which the depth first search algorithm explore the graph till termination, searching from right to left until it reaches one of the goal nodes.


Answer: S,C,J,T,I1

Question 9:
Advanced Consider a hash function that distributes keys uniformly. The hash table size is 20. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed 0.5.
a. 10
b. 7
c. 6
d. 5

Answer: a) 10
Question 10:
Eesha was in a wonderland where she saw a treasure trove of seven items of various values (in lakhs) and weights (in kgs) as per the table given below.
items    values    weight
1              12             4
2              10             6
3               8              5
4              11             7
5              14             3
6               5            10
7               5            12
She wanted to bring back maximum value of items but she was not able to carry more than 10 kgs.  Using dynamic programing, what is the maximum value of of the items that she could carry back with her.

Answer: 26


Coding: 1 question , Time: 30mins 

Problem Statement:

Consider the following series: 1,1,2,3,4,9,8,27,16,81,32,243,64,729,128,2187…
This series is a mixture of 2 series - all the odd terms in this series form a geometric series and all the even terms form yet another geometric series. Write a program to find the Nth term in the series.
The value N in a positive integer that should be read from STDIN. The Nth term that is calculated by the program should be written to STDOUT. Other than value of n th term,no other character / string or message should be written to STDOUT. For example , if N=16, the 16th term in the series is 2187, so only value 2187 should be printed to STDOUT.

You can assume that N will not exceed 30.

Source code:

#include<stdio.h>
long int pow(int r, int n);
int main()
{
            int n;
            long int res;
            scanf("%d",&n);
            if(n%2==0)
            {
                        res=pow(3,n/2);
            }
            else
            res=pow(2,n/2+1);
            printf("%ld",res);
            return 0;
}
long int pow(int r, int n)
{
int i;
long int ans=1;
if(n==1)
return 1;
for(i=1;i<n;i++)
{
 ans=ans*r;

}
return ans;
}

No comments:

Post a Comment

CTS Written test results of Vijayawada, Guntur, Ongole, Godarvari Districts were out.  Tentative dates of TR and HR are 24th and 25th Nov...