Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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';
}
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
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.
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.