C Programming Project 4
C Programming Project 4
Aerospace School
Project project.4: Matrices
Exercise 1
Write a C program that makes the addition of two Matrices that have the
same size (2x2).
Test Data:
Input the size of the square matrix (less than 5): 2
Input elements in the first matrix :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Input elements in the second matrix :
element - [0],[0] : 5
element - [0],[1] : 6
element - [1],[0] : 7
element - [1],[1] : 8
Expected Output:
The First matrix is :
1 2
3 4
The Second matrix is :
5 6
7 8
The Addition of two matrix is :
6 8
10 12
Exercise 2
Write a C program to find the transpose of given matrix.
Test Data:
Input the rows and columns of the matrix : 2 2
Input elements in the first matrix :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output:
The matrix is :
1 2
3 4
The transpose of a matrix is :
1 3
2 4
Exercise-3
Write a program in C to accept two matrices and check whether they are
equal.
Test Data:
Input Rows and Columns of the 1st matrix :2 2
Input Rows and Columns of the 2nd matrix :2 2
Input elements in the first matrix :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Input elements in the second matrix :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output:
The first matrix is :
1 2
3 4
The second matrix is :
1 2
3 4
The Matrices can be compared :
Two matrices are equal.
Exercise-4
Write a program in C to check whether a given matrix is an identity matrix.
Test Data:
Input number of Rows for the matrix :3
Input number of Columns for the matrix :3
Input elements in the first matrix :
element - [0],[0] : 1
element - [0],[1] : 0
element - [0],[2] : 0
element - [1],[0] : 0
element - [1],[1] : 1
element - [1],[2] : 0
element - [2],[0] : 0
element - [2],[1] : 0
element - [2],[2] : 1
Expected Output:
The matrix is:
1 0 0
0 1 0
0 0 1
The matrix is an identity matrix.
Exercise-5
Write a program in C to find the number occurring odd number of times in an
array.
All numbers occur even number of times except one number which occurs odd
number of times.
Expected Output:
The given array is : 8 3 8 5 4 3 4 3 5
The element odd number of times is : 3