### Calculate the determinant: Ask the user to choose the row

**Assignment Detail:- ** C Programming Part
You must make sure that your code runs on Codeblocks -It is your responsibility to submit a -c code that compiles and runs-
Briefing:This task will assess your ability to solve a problem using these C programming elements: repetition -e-g- for-- or while---, selection -if-, structures, two dimensional arrays, pointers, I/O and functions- Your task is to write a C program to:
• **Allow the user to input the size of a matrix- The contents of the matrix are read in from a file, which has a list of 100 float numbers -numbers in the file are <100-00-- If the matrix is 3x2, then the first 2 numbers in the list form the first row, the second 2 numbers in the list form the second row ---and so on--• The matrix must have between 1 and 10 columns and between 1 and 10 rows- The matrix size -rows x columns- is determined by the user, and this information is stored in a struct matrix -specified below- in members int nrows and int ncols-• The contents of the matrix will also be stored in the struct matrix in member float mValues-10--10--• Calculate the determinant: Ask the user to choose the row and column to form a 2x2 matrix, which is a subset of the original matrix- The 2x2 matrix contents must be stored in a new struct matrix variable, along with its size- The determinant of this matrix is then calculated- -See sample run of program below--• Find the inverse of the 2x2 matrix: The inverse matrix contents must be stored in a new struct matrix variable, along with its size- ##• Loop from ** to ##, but allow the user some way of exiting the loop and stopping the program
The program shall define a structure to hold information about the matrices as follows -only define one structure, but declare 3 structure variables: one for the original matrix, one for the 2x2 sub matrix and one for the inverse-:
struct matrix{float mValues-10--10-; // to hold the values in the matrix, up to 10 rows x 10 columnsint nrows; // to hold the number of rows used in mValuesint ncols; // to hold the number of columns used in mValues};
Notes -refer to mark scheme for more details-:
1- The array that holds the matrix values has maximum size 10x10, which means that the program must be able to work with any array up to that size- For this program, the minimum array size allowed is 1 x 1-
2- A sample -txt file with 100 numbers is available on ACS130 Blackboard- Please note that you will need to test your code thoroughly to cover every possible scenario -eg to get a det=0-- I will be using a different test data to test your program-
3- The program must display to the screen the contents of each matrix in the program, after it has been input or created-
4- The program must allow both square and non-square matrices, e-g- 3 x 3 is square, 3 x 4 is not square-
5- You must program defensively- The program must check for out ofrange values for rows and columns at every possible instance- The program must ask the user to enter again if incorrect- You also need to check if the input file is available- You also need to take into consideration things like: possibility of generating a 2x2 matrix -because the input matrix is smaller, eg, 2x1-, having a 1x1 matrix, and finding the inverse when the determinant is 0 or does not exist-
6- You cannot use global variables- You will get 0 for the whole code- #define can be used-
7- You cannot use while-1- loops- You will get 0 for the whole code- You can use a while-OK- loop where OK is a variable that is, for eg, 0 or 1
8- You cannot use break -unless it is part of a switch case--
9- You cannot use goto, continue, jump-
10- The program must include main- - and the following 4 functions- The function prototypes must be as follows:
void matrixInput-struct matrix *mat, FILE *in-; /* to input the size -number of rows and columns- of the matrix, and read in the values from the file -using fscanf- into the 2D array that makes up the matrix */ NOTE, the file opening and checking occurs in main--, eg FILE*fin; fin=fopen-" xyz-txt",'r'-; then use fin in the function call-
void matrixDisplay-struct matrix mat-; /* to display the values in the 2D array that makes up the matrix*/
float matrixDeterminant-struct matrix m1, struct matrix *m2, int*check-; /* to find the determinant of M2, where M2 is a 2x2 subset matrix of m1; returns determinant to main- If determinant is not equal to 0, check =1; if determinant=0, cheCK=2, otherwise check is 0 -when size of matrix <2x2-- check variable is needed for the inverse- This function does not display either M1 or M2- */
void matrixInverse-struct matrix m2, float determinant, struct matrix*m3-; /* to find the inverse -if possible- of the 2X2 matrix; this function does not display either M2 or m3- */
11- You are free to add extra functions, for example, for out-of-range checks -for rows and columns-, or any other defensive programming required, but you must have the 4 functions listed above-
Attachment:- C Programming - Structures and 2D arrays-rar

## Post a Comment