Sei sulla pagina 1di 2

University Of Hyderabad

School of Computer & Information Sciences


CA404 – Programming Methodology
Major Examination MCA I Semester Max. Marks: 60
Section – A (Answer any 8 questions 8 X 6 = 48 Marks)
1. Explain about the different phases of problem solving and programming?
2. What is scope and life time of a variable? Explain about different scopes of a variable?
3. Explain the differences between sequential access and random access file processing. In
what situations one is preferred over the other.
4. Explain about different storage classes of C along with the default values of the variables
declared of each class?
5. Show how the list of elements {8, 2, 4, 7, 1, 6, 3, 5} are sorted in ascending order using
insertion sort and quick sort?
6. Write a recursive C function to compute the determinant of an NXN square matrix.
7. Identify the errors (compile time and run time errors) in the following program.
#include<stdio.h>
void f( int p, int q)
{
return p + q;
}

int main ()
{
int i, j, n, a[50][50];
int *p, *q;
char *s;
scanf("%d", &n);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
a[i][j] = f(i, j);
p = *(a + 2);
q = *(*( a + 2) + 2);
printf("%u\n", p + q);
s[0] = '\0';
}

8. Write the following C functions related to linked lists.


a) Write a recursive C function which shrinks a linked list by removing elements at
(odd) positions 1, 3 , 5 and so on.
b) Write an iterative C function to display list elements (data part) in reverse order.

1
9. Suppose an array is used to represent a set, write C functions for the following set
operations.
a. Function which returns the difference of sets A and B (A - B)
b. Set symmetric difference of sets A and B ((A-B) U (B-A))

10. In an upper triangular matrix all the elements below the main diagonal are zeros, so if we
use a two dimensional array to store the matrix there is wastage of memory. To save the
memory a single dimensional array is used to store the elements(left to right and row by
row) of an upper triangle square matrix of size N X N. Assuming array index, row index and
column index starts from 0, write expressions using any repetition structures to compute
the following.
a) Sum of the elements of the ith row
b) Sum of the elements of jth column
c) Sum of the elements of the main diagonal

Section – B (Answer all the questions 6 + 6 = 12 Marks)

11. Consider a two dimensional matrix M of size N X N where each element of the matrix is
either 0 or 1. Moreover, all the rows of the matrix have 0’s followed by all 1’s. That is the
first part of the row consists of 0’s (if at all the row contains any 0’s) and the rest contains
1’s (if at all row contains any 1’s).
Example 5 X 5 Matrix:

To save space a single dimensional random access list A of size N is used to store the matrix
information with each element represents the index of the first 1 of that row (if there is no
1 in the row N is stored). Assume that matrix/list index starts from 0.

For the above example 5 X 5 matrix, A = {3, 0, 4, 5, 2}.

Write an algorithm which accepts the simplified one-dimensional list A of the matrix M as
input and prints the Transpose of the matrix M in row by row order.

12. Write a recursive C function which takes a string containing characters ‘x’s (‘x’: don’t care
symbol), ‘0’s and ‘1’s, write a recursive function that prints all possible binary strings for the
input string. For example, the string “1x0x” represents the numbers 1000, 1001, 1100, 1101.
The string “xx1” represents 001 , 011 , 101 , 111.

Potrebbero piacerti anche