Turn this C Program into DATA ABSTRACTION: Files: main.c, matrix.h, matrix.c Code: #include #define ROW 6 #define COL 6 //function prototypes void add(int matrixResult[][COL],int matrixA[] [COL],int matrixB[][COL],int row,int col); void subtract(int matrixResult[][COL],int matrixA[] [COL],int matrixB[][COL],int row,int col); void multiply(int matrixResult[][COL],int matrixA[] [COL],int matrixB[][COL],int row,int col); void display(int matrix[][COL]); //main function int main() { //declare and initialize 6*6 matrix int matrixA[][COL] = {{10,20,30,40,50,60},{7,8,9,10,11,12}, {13,14,15,16,17,18},{19,20,21,22,23,24}, {25,26,27,28,29,30},{31,32,33,34,35,36}}; //declare and initialize 6*6 matrix intmatrixB[][COL] = {{1,2,3,4,5,6},{17,28,19,78,34,12}, {33,14,25,16,17,18},{19,22,21,22,23,24}, {19,26,11,28,29,30},{30,32,23,34,15,16}}; int matrixResult[ROW][COL]; printf("Addition of two matrices:\n"); add(matrixResult,matrixA,matrixB,ROW,COL); printf("\n\nDifference of two matrices:\n"); subtract(matrixResult,matrixA,matrixB,ROW,COL); printf("\n\nProduct of two matrices:\n"); multiply(matrixResult,matrixA,matrixB,ROW,COL); return 0; } //function to add two 6*6 matrix void add(int matrixResult[][COL],int matrixA[][COL], int matrixB[][COL],int row,int col) { for(int i=0;i
Turn this C
Files: main.c, matrix.h, matrix.c
Code:
#include <stdio.h>
#define ROW 6
#define COL 6
//function prototypes
void add(int matrixResult[][COL],int matrixA[]
[COL],int matrixB[][COL],int row,int col);
void subtract(int matrixResult[][COL],int matrixA[]
[COL],int matrixB[][COL],int row,int col);
void multiply(int matrixResult[][COL],int matrixA[]
[COL],int matrixB[][COL],int row,int col);
void display(int matrix[][COL]);
//main function
int main()
{
//declare and initialize 6*6 matrix
int matrixA[][COL] = {{10,20,30,40,50,60},{7,8,9,10,11,12},
{13,14,15,16,17,18},{19,20,21,22,23,24},
{25,26,27,28,29,30},{31,32,33,34,35,36}};
//declare and initialize 6*6 matrix
intmatrixB[][COL] = {{1,2,3,4,5,6},{17,28,19,78,34,12},
{33,14,25,16,17,18},{19,22,21,22,23,24},
{19,26,11,28,29,30},{30,32,23,34,15,16}};
int matrixResult[ROW][COL];
printf("Addition of two matrices:\n");
add(matrixResult,matrixA,matrixB,ROW,COL);
printf("\n\nDifference of two matrices:\n");
subtract(matrixResult,matrixA,matrixB,ROW,COL);
printf("\n\nProduct of two matrices:\n");
multiply(matrixResult,matrixA,matrixB,ROW,COL);
return 0;
}
//function to add two 6*6 matrix
void add(int matrixResult[][COL],int matrixA[][COL],
int matrixB[][COL],int row,int col)
{
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
matrixResult[i][j] = matrixA[i][j] + matrixB[i][j];
display(matrixResult);
}
//function to subtract two 6*6 matrix
void subtract(int matrixResult[][COL],int matrixA[][COL],
int matrixB[][COL],int row,int col)
{
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
matrixResult[i][j] = matrixA[i][j] - matrixB[i][j];
display(matrixResult);
}
//function to multiply two 6*6 matrix
void multiply(int matrixResult[][COL],int matrixA[][COL],
int matrixB[][COL],int row,int col)
{
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
matrixResult[i][j] = 0; //assigning 0
//find product
for(int k=0;k<row;k++)
matrixResult[i][j]+ = matrixA[i][k] * matrixB[k][j];
}
}
display(matrixResult);
}
//function to display 6*6 matrix
void display(int matrix[][COL],
{
for(int i=0;i<ROW;i++)
{
for(int j=0;j<COL;j++)
printf("%d\t",matrix[i][j]);
printf("\n"); //new line
}
}
Step by step
Solved in 3 steps with 1 images