C Programs
1.Print a given matrix in spiral form
Given a 2-D array, print it in spiral form. See the following examples.
2. Zigzag (or diagonal) traversal of Matrix
Given a 2D matrix, print all elements of the given matrix in diagonal order. For example, consider the following 5 X 4 input matrix.
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
Diagonal printing of the above matrix is
1
5 2
9 6 3
13 10 7 4
17 14 11 8
18 15 12
19 16
20
3.Print a given matrix in zigzag form
Given a 2D array, print it in zigzag form
4. Find the frequency of occurrences of sub-string in given string.
Examples:
Input : man (sub-string)
dhimanman (string)
Output : 2
Input : nn (sub-string)
Banana (String)
Output : 0
5.Write a C program using Pointer to compute the
(a) The product of two matrices of any orders
(b) The transpose of the product matrix
6. Write a Program in C to determine whether a given 3 x 3 matrix is a magic square or not. (A magic square is a matrix whose sum of rows, columns and diagonals is the same). An example is given below:
8 1 6
3 5 7
4 9 2
Note: Please include the possible test cases (if required).
7.Write a function which take a string of maximum length 4 to print all permutations of a given string using pointers.
Example:
Below are the permutations of string ABC.
Result: ABC ACB BAC BCA CBA CAB
8.Design and code an interactive and modular program that will use functions to enter a matrix of m by n size, compute column averages and row averages and print them. (Note: Your program should work for variable dimensions).
9.Printing string in plus ‘+’ pattern in the matrix
Given a string, print it inside a matrix in such a way that a ‘plus’ is formed.
Input: TOP
Output:
X T X
T O P
X P X
Input: FEVER
Output:
X X F X X
X X E X X
F E V E R
X X E X X
X X R X X
10.C program to print Pascal triangle
11.Write a C program to print the following pattern:
*
* *
* * *
* * * *
* *
* * *
* * * *
* *
* * * * * *
* * * * * * * * * *
* * * * * * * * * * *
* * * * * *
* * * * * * * * * *
* * * * * * * * * * *
* *
* *
* * * *
* * * *
* * * * *
* * * *
* * * *
* *
* *
* *
* * * *
* * * *
* * * * *
* * * *
* * * *
* *
* *
* * * * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * * * *
* * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * *
* * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
* * * * * * * * * * * * * *
* * * * * * * * * *
* * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
*
* * *
* * * * *
* * * * * * *
* *
* * * *
* * * * * *
* * * * * * *
* * * * * *
* * * *
* *
* * * * * * *
* * * * *
* * *
*
* * *
* * * * *
* * * * * * *
* *
* * * *
* * * * * *
* * * * * * *
* * * * * *
* * * *
* *
* * * * * * *
* * * * *
* * *
*
* * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *
* * * * * *
* * * * * *
* * *
* * * * * *
* * * * * *
* * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *
* * * * * *
* * * * * *
* * *
* * * * * *
* * * * * *
* * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * *