University of Sheffield: ACS130 C Programming Assignment - Matrix

Verified

Added on  2022/08/28

|7
|922
|16
Homework Assignment
AI Summary
This C programming assignment solution demonstrates matrix operations using the C programming language. The assignment focuses on calculating determinants and inverses of matrices, utilizing structures, two-dimensional arrays, loops (for and while), conditional statements (if/else), pointers, and input/output operations, including reading matrix data from a text file. The code is structured with functions for matrix input, display, determinant calculation, and inverse calculation. The program is designed to be run in CodeBlocks and includes header files, structure definitions, and the main function, which orchestrates the matrix operations. The solution showcases how to handle matrix dimensions, read matrix values from a file, and display the results of the determinant and inverse calculations. The code is well-commented, providing insights into the implementation of each function and the overall program flow.
Document Page
Running head: C PROGRAMMING
C PROGRAMMING
Enter the name of the Student:
Enter the name of the University:
Author note:
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1C PROGRAMMING
The assignment is mainly written in the C programming language. In this assignment,
the functions of the elements of the C programming are noticed. The loop such as for, while,
the if else method for selection, structures, pointers, I/O, functions and two dimensional
arrays are used to complete this assignment.
Figure 1: Coding
(Source: Created by author)
These three are the header file which are used in this assignment. The header file is
the file with the extension that consists the declarations of the C function also the macro
definition for sharing in between many source files. Some header files are in built with the
compiler such as the stdio.h.
Figure 2: Coding
(Source: Created by author)
The structure is the user defined data type and it makes a data type which can use for
combining items of the different types into a solo type. Here a structure is created to hold the
information about the matrices. The name is used to keep the single character name of this
matrix like A, B etc. and the data type of this is char. A two dimensional array is used in this
Document Page
2C PROGRAMMING
named mValues which is used to keep the values in this matrix up to the 10 no of rows and
10 no of columns. The data type of this is float. Then nrows of integer data type is created
that is used to keep the number of rows which is used in the mValues. And also ncols is
created of integer data type that is used to keep the column numbers that is used in the
mValues.
Figure 3: Coding
(Source: Created by author)
The main method is started. In this main method a variable is generated of the
structure. Some variables are made here for future use. Then a function named matrixInput is
created and call to create the matrix. Another function is created named matrixDisplay that is
used to display the created matrix. After that another function is created to calculate the
determinant of the matrix which is named as matrixDeterminant and the matrixDisplay is
again used to display this matrix. And last function which is created is matrixInverse that is
calculated to inverse of the determinant and the matrixDisplay is used to display the matrix
again.
Document Page
3C PROGRAMMING
Figure 4: Coding
(Source: Created by author)
Figure 5: Coding
(Source: Created by author)
After that this function matrixInput is created which is void type that it is return null.
It is mainly used to input the size of the matrix that is number of the rows and columns and
name of this matrix. It also read the values from a text file using fscanf into this 2D array
which creates the matrix.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4C PROGRAMMING
Figure 6: Coding
(Source: Created by author)
It is a function named matrixDisplay which is used to display the created matrix. Also
values in the two dimensional array which makes the matrix. The for loop is used to enter to
print the created matrix in the output screen.
Figure 7: Coding
Document Page
5C PROGRAMMING
(Source: Created by author)
It is a function named matrixDeterminant which is used to calculate the determinant
of the matrix. It is used to fine the determinant of the m2 in which m2 is the 2×2 subset
matrix of the m1 that is the actual matrix which is created in the matrixInput function. This
function returns the determinant to the main function. Also this function does not show the
m1 or m2, only name of the matrix is entered here.
Figure 8: Coding
(Source: Created by author)
The for loop is used to loop for the number of rows and also the columns that a user
has entered. And after that it can calculate the determinant and print the value of it in the
output screen.
Document Page
6C PROGRAMMING
Figure 9: Output
(Source: Created by author)
This is the output of this programming. The values of the matrix are read from a text
file named matrix.txt. This program read the text file and after that the value is stored in the
two dimensional array and by using the matrixDisplay function, this value of the matrix is
shown in the output screen. User can give the desired number of rows and columns and after
that the desired matrix is showed in the output screen. After that user can select the row
number and column number from where user can start the matrix to calculate the determinant
of this set of matrix.
In this program, the C programming language is used and the CodeBlocks is used. It
is the program to calculate the determinant and also the inverse of the determinant. In this
code several things are used such as structure, for loop, if statement, pointers, I/O that is read
from a text file for input, functions and two dimensional array.
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]