Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #ifndef dynamicmatrix_h
- #define dynamicmatrix_h
- #define R 7
- #define C 7
- void display(int a[][C], int row, int column);
- void displayTranspose(int a[][C], int row, int column);
- float average(int a[][C], int row, int column);
- int findlowest(int a[][C], int row, int column);
- int isSquare(int row, int column);
- void matrixSum(int A[][C], int rowA, int colA, int B[][C], int rowB, int colB);
- void matrixProduct(int A[][C], int rowA, int colA, int B[][C], int rowB, int colB);
- void input(int(*input)[C], int rowS, int colS);
- void sizeinput(int *row, int *column, char designator);
- #endif
- #include <stdio.h>
- #include <conio.h>
- #include "dynamicmatrix.h"
- void main()
- {
- int matrixA[R][C];
- int matrixB[R][C];
- int rowA, colA, rowB,colB;
- sizeinput(&rowA, &colA, 'A');
- printf("\nPlease enter values for Matrix A");
- input(matrixA, rowA, colA);
- printf("\n- The numbers in matrix A are: \n");
- display(matrixA, rowA, colA);
- sizeinput(&rowB, &colB, 'B');
- printf("\nPlease enter values for Matrix B");
- input(matrixB, rowB, colB);
- printf("\n- The numbers in matrix B are: \n");
- display(matrixB, rowB, colB);
- printf ("\n\n\n- The average of the numbers in matrix A is: %.2f", average(matrixA, rowA, colA));
- printf ("\n\n- The transposed numbers in matrix A are: \n");
- displayTranspose(matrixA, rowA, colA);
- printf ("\n\n\n- The lowest number in matrix A is: %d", findlowest(matrixA, rowA, colA));
- printf("\nFor matrix A:");
- switch(isSquare(rowA, colA))
- {
- case 1: printf ("\n\n- The matrix is a square.");
- break;
- case 0: printf ("\n\n- The matrix is not a square.");
- break;
- }
- printf("\nFor matrix B:");
- switch(isSquare(rowB, colB))
- {
- case 1: printf ("\n\n- The matrix is a square.");
- break;
- case 0: printf ("\n\n- The matrix is not a square.");
- break;
- }
- matrixSum(matrixA, rowA, colA, matrixB, rowB, colB);
- matrixProduct(matrixA, rowA, colA, matrixB, rowB, colB);
- _getch();
- }
- #include <stdio.h>
- #include <conio.h>
- #include "dynamicmatrix.h"
- void sizeinput(int *row, int *column, char designator)
- {
- int rowinput, columninput;
- printf_s("\nPlease enter the following information for matrix %c\n", designator);
- printf_s("\n Row: "); scanf_s("%d", &rowinput);
- printf_s("\nColumn: "); scanf_s("%d", &columninput);
- *row=rowinput;
- *column=columninput;
- }
- void input(int(*input)[C], int rowS, int colS)
- {
- int row, col;
- for (row = 0; row < rowS; row++)
- {
- for (col = 0; col < colS; col++)
- {
- printf("\nEnter value for pos[%d,%d]\n", col, row);
- scanf_s("%d", &input[row][col]);
- }
- }
- }
- void matrixProduct(int A[][C], int rowA, int colA, int B[][C], int rowB, int colB)
- {
- int psum = 0, product[R][C];
- if (colA==rowB)
- {
- for (int row = 0; row < rowA; row++)
- {
- for (int col = 0; col < colB; col++)
- {
- for (int control = 0; control < colA; control++)
- {
- psum = psum + A[row][control] * B[control][col];
- }
- product[row][col] = psum;
- psum = 0;
- }
- }
- printf("\nThe product of matrix A and B is: \n");
- display(product, rowA, colB);
- }
- else
- printf_s("\nDimension mismatch! Cannot perform multiplication.");
- }
- void matrixSum(int A[][C], int rowA, int colA, int B[][C], int rowB, int colB)
- {
- int row, col, sum[R][C];
- if (rowA==rowB && colA==colB)
- {
- for (row = 0; row < rowA; row++)
- {
- for (col = 0; col < colB; col++)
- {
- sum[row][col] = A[row][col] + B[row][col];
- }
- }
- printf("\nThe sum of matrix A and B is: \n");
- display(sum, row, col);
- }
- else printf_s("\nDimension mismatch! Cannot perform addition");
- }
- void displayTranspose(int a[][C], int row, int column)
- {
- for (int rowD = 0; rowD<column; rowD++)
- {
- printf("\n");
- for (int columnD = 0; columnD<row; columnD++)
- {
- printf(" %d ", a[columnD][rowD]);
- }
- }
- }
- void display(int a[][C], int row, int column)
- {
- for (int rowD = 0; rowD<row; rowD++)
- {
- printf("\n");
- for (int columnD = 0; columnD<column; columnD++)
- {
- printf(" %d ", a[rowD][columnD]);
- }
- }
- }
- float average(int a[][C], int row, int column)
- {
- float total=0;
- int count=0;
- for(int rowD=0; rowD<row; rowD++)
- {
- for(int columnD=0; columnD<column; columnD++)
- {
- total+=a[rowD][columnD];
- count++;
- }
- }
- return total/count;
- }
- int findlowest(int a[][C], int row, int column)
- {
- int lowest=10;
- for(int rowD=0; rowD<row; rowD++)
- {
- for(int columnD=0; columnD<column; columnD++)
- {
- if (a[rowD][columnD]<lowest)
- lowest=a[rowD][columnD];
- }
- }
- return lowest;
- }
- int isSquare(int row, int column)
- {
- if (row==column)
- return 1;
- else
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment