Monday, August 31, 2015

AMCAT COMPUTER PROGRAMMMING PREVIOUS QUESTIONS (PAPERS)-13



121. I have a problem to solve which takes as input a number n property that given the solution for (n
programming technique will I use to solve such a problem?
A. Iteration         B. Decision-making       C. Object Oriented Programming   D. Recursion
Solution: Answer will be option B.

122. Here is an infix notation: ((A+B)*C-(D-E))^(F+G) Choose the correct postfix notation of the above from the given options?
A. AB+CD*E--FG+^         B. AB+C*DE--FG+^       C. AB+C*DE-FG-+^   D. A+BC*DE-FG-+^
Solution: Answer will be option B.

123. 123. If the depth of a tree is 3 levels, then what is the size of the Tree?
A. 2                        B. 4                      C. 6                      D. 8
Solution: Answer will be option D.

124. One of the following options is a form of access used to add and remove nodes from a queue.
A. LIFO               B. FIFO               C. Both LIFO and FIFO    D. None of these
Solution: Answer will be option C.


125. What is the time complexity of adding three matrices of size NXN cell-by-cell?
A. O (N)                                B. O (N^2)                           C. O (N^3)                           D. None of these
Solution: Answer will be option B.

126. Choose the correct answer. A sort which uses the binary tree concept such that any number in the tree is larger than all the numbers in the sub tree  below it is called
A. Selection sort                                            B. Insertion sort                                                C. Heap sort                       D. Quick sort
Solution: Answer will be option C.


AMCAT COMPUTER PROGRAMMMING PREVIOUS QUESTIONS (PAPERS)-12



111. Which of the following accessibility modes can be the speciļ¬er of a top level class?
1. Private                       2. Protected                     3. Public                              4. No modifier
A. only 3                       B. only 44                        C. Both 1 and 3                    D. Both 2 and 3                 E. Both 3 and 4
Solution: Answer will be Option A.

112. A language has 28 different letters in total. Each word in language is composed of maximum 7 letters .you want to create a data type to store a word of this language. You decide to store the word as an array of letters. How many bits will you assigns to the database to store all kind of word of language?
A. 7                                                     B. 35                                                   C. 28                                                   D. 196
Solution: Answer will be Option B.

To represent 28 different letters we need 5 bits per each (2^5=32). Each word contains max letters 7. Hence number of bits=5*7=35.

113. Recursive function is executed in a   ___________________________
A. Last in First Out Order                 B. First in First Out Order           C. Parallel Fashion            D. All of the above
Solution: Answer will be Option A.

114. Yukta created an interface to use it in different parts of the program by implementing it. But she forgot to specify the access specifier for each contained method. What will be the access specifier of the methods that will be inherited/implemented?
A. Public                                 B. Private                                    C. Protected                    D. An error will be generated
Solution: Answer will be Option A.

115. Which of the following statements are true?
1)An Arithmetic left shift multiplies a signed number by two
2)An Arithmetic right shift divides a signed number by two
3)Mask operation is an AND micro-operation and insert is an OR micro-operation
4)In a logical shift, the serial input to the shift is one
A. Both 1 and 2                      B. Both 3 and 4                                       C. 1, 2 and 3                                     D. 2, 3 and 4
Solution: Answer will be Option C.

116. Choose the correct answer. A Queue is implemented by a linear array of size 10 (and not as a circularly connected array). Front and Rear are represented as an index in the array. To add an element, the rear index is incremented and the element is added. To delete an element, the front index is incremented. The following operations are done on an empty queue.
ADD 1; DELETE; ADD 2; ADD 3; ADD 4; DELETE, DELETE.
After this set of operations, what is the maximum capacity of the queue?
A. 6                                 B. 7                                  C. 10                               D. None of these

Solution: Answer will be option B.
In queue initially the both Front and Rear assigned by the value -1 means the queue is empty. The size of the queue is 10 (array index no from 0 to 9).
ADD 1 it will increment both Front and Rear (in case of first element)
DELETE deletion of element set the Front and Rear to -1(queue is empty)
ADD 2 Front = 0 ,Rear = 0
ADD 3 Front = 0 ,Rear = 1
ADD 4 Front = 0 ,Rear = 2
DELETE Front = 1 ,Rear = 2
DELETE Front = 2 ,Rear = 2
Now the empty location in the queue is 7 so the maximum capacity of queue is 7 . In spite 2 location is empty in left side of the last element 4 but queue cannot access these location as the front on the location 2 this is the disadvantage of simple to queue to overcome this problem circular queue is implemented.

117. A tree has 5 levels and each has either 4 children or no children. All nodes on the same level have the same number of children. How many nodes are there in the tree? (Root is Level 1)
A. 341                                   B. 256                              C. 1024                               D. None of these
Solution: Answer will be option A. 1 + 4 + 16 + 64 + 256

118. A 8-bit signed integer has the following range?
A. 0 to 255                           B. -128 to 127                  C. -255 to 254                              D. 0 to 509
Solution: Answer will be option B.

119. What will be the output of the following code statements?
integer x = 34. 54, y = 20, z =
print ( y > 50 AND z > 10 or x > 30 )
A. 0                        B. 1                      C. -1                    D. 10
Solution: Answer will be option B.

120. Pankaj makes a program to print the product of cubes of the first 10 whole numbers
She writes the following program:
integer x = 0 // statement 1
integer sum = 0 // statement 2
while ( x < 10 ) // statement 3
{
sum = x*x*x // statement 4
x = x + 1 // statement 5
}
print sum // statement 6
Is her program correct? If not, which statement will you modify to correct it?
A. No error, the program is correct         B. Statement 1           C. Statement 4      D. statement 6
Solution: Answer will be option C.


C Programs on flow control statements (if, switch, loop, break and continue)-6

2015 & 2016 Batch Freshers Registration Link

JOIN MY FACEBOOK GROUP FOR UPDATES 

C Program to Find GCD of two Numbers

Note: GCD of any two numbers( say a and b)  lies between 1 and minimum of two numbers

LCM(a,b) * GCD(a,b)=a*b

main()
{
          int num1, num2, min,i;
          printf("Enter two integers: ");
          scanf("%d %d", &num1, &num2);
 
min=(num1>num2)?num2:num1; /* minimum value is stored in variable min */
          for(i=min;i>=1;--i)
          {
                    if(num1%i==0 && num2%i==0)
                    {
                                       printf("HCF of %d and %d is %d", num1, num2,i);
                             break;
                    }
          }
}



C Program to Find LCM of two Numbers

Note: LCM of any two numbers( say a and b)  lies between maximum of two given numbers and product of two numbers

LCM(a,b) * GCD(a,b)=a*b

main()
{
          int num1, num2, max;
          printf("Enter two positive integers: ");
          scanf("%d %d", &num1, &num2);
          max=(num1>num2) ? num1 : num2; /* maximum value is stored in variable max */
          while(1)                       /* Always true. */
          {
                    if(max%num1==0 && max%num2==0)
                    {
                                       printf("LCM of %d and %d is %d", num1, num2,max);
                                       break;          /* while loop terminates. */
                    }
                    ++max;
          }
}





C Program to Display Fibonacci Series

The Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
The next number is found by adding up the two numbers before it.
    The 2 is found by adding the two numbers before it (1+1)
    Similarly, the 3 is found by adding the two numbers before it (1+2),
    And the 5 is (2+3),
    and so on!
Example: the next number in the sequence above is 21+34 = 55
It is that simple!
Here is a longer list:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811
/* Displaying Fibonacci sequence up to nth term where n is entered by user. */
#include <stdio.h>
int main()
{
          int count, n, t1=0, t2=1, display=0;
          printf("Enter number of terms: ");
          scanf("%d",&n);
          printf("Fibonacci Series: %d+%d+", t1, t2); /* Displaying first two terms */
          count=2;    /* count=2 because first two terms are already displayed. */
          while (count<n) 
          {
                    display=t1+t2;
                    t1=t2;
                    t2=display;
                    ++count;
                    printf("%d+",display);
          }
}

C Programs on flow control statements (if, switch, loop, break and continue)-5

2015 & 2016 Batch Freshers Registration Link

JOIN MY FACEBOOK GROUP FOR UPDATES 

C pattern programs

C program to print following pyramid pattern of stars

                                 
main()
{
          int row, c, n, temp;
          printf("Enter the number of rows in pyramid of stars you wish to see ");
          scanf("%d",&n);

          temp = n;
          for ( row = 1 ; row <= n ; row++ )
          {
                    /* for spacing purpose */
                    for ( c = 1 ; c < temp ; c++ )
                             printf(" ");
      
temp--;
/* for printing stars */
                    for ( c = 1 ; c <= 2*row - 1 ; c++ )
                             printf("*");
                    printf("\n");
          }
 }

Write a c program to print Pascal triangle.

In mathematics, Pascal's triangle is a triangular array of the binomial coefficients. In much of the Western world it is named after French mathematician Blaise Pascal, although other mathematicians studied it centuries before him in India, Iran, China, Germany, and Italy.


long factorial(int);
main()
{
          int row, c, n, temp;
          printf("Enter the number of rows you wish to see in pascal triangle\n");
          scanf("%d",&n);

          temp = n;
          for ( row = 0 ; row < n ; row++ )
          {
                    /* for spacing purpose */
                    for ( c = 1 ; c < temp ; c++ )
                             printf(" ");
      
temp--;
/* for printing stars */
                    for ( c = 0 ; c <= row ; c++ )
                             printf("%ld ",factorial(row)/(factorial(c)*factorial(row-c)));
                    printf("\n");
          }
 }

long factorial(int n)
{
          int c;
          long int result = 1;
          for (c = 1; c <= n; c++)
                   result = result*c;
          return result;
}

Write a c program for Floyd’s triangle.
This program prints Floyd's triangle. Number of rows of Floyd's triangle to print is entered by the user. First four rows of Floyd's triangle are as follows :-
1
2 3
4 5 6
7 8 9 10
It's clear that in Floyd's triangle nth row contains n numbers.

main()
{
int n, row,  c, a = 1;

          printf("Enter the number of rows of Floyd's triangle to print\n");
          scanf("%d", &n);

          for (row = 1; row <= n; row++)
          {
                    for (c = 1; c <= row; c++)
                    {
                              printf("%d ",a);
                               a++;
                    }
                    printf("\n");
          }

 }

Contact Geek Placement Preparation

Name

Email *

Message *