0% found this document useful (0 votes)
50 views12 pages

Term Paper MATRICESpdf

The document describes a C program for performing basic matrix operations like addition, subtraction, multiplication, and transpose. It outlines the concepts and code for each operation, taking input from the user and outputting the results. The program allows for efficient and accurate matrix calculations in C.

Uploaded by

Aditi Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views12 pages

Term Paper MATRICESpdf

The document describes a C program for performing basic matrix operations like addition, subtraction, multiplication, and transpose. It outlines the concepts and code for each operation, taking input from the user and outputting the results. The program allows for efficient and accurate matrix calculations in C.

Uploaded by

Aditi Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Term Paper

on
MATRIX OPERATIONS USING C
of
Programming for problem solving-ES-CS201 TH

Submitted by:
Aditi Kumari - 11500220021
Abhik Chakraborty - 11500220022
Anindya Biswas - 11500220023
Soumyadip Bhattacharyya - 11500220024

First year, Second Sem-2021

Department of Information Technology

B. P. Poddar Institute of Management and Technology


MATRIX OPERATIONS USING C

ABSTRACT- In this research paper, a c Program is designed to perform matrix addition,


subtraction, multiplication, and transpose. We have developed appropriate C
functions for the following to perform matrix addition, subtraction, multiplication, and
transpose operations.

1.INTODUCTION

In mathematics, a matrix (plural matrices) is a rectangular array or table of numbers, symbols,


or expressions, arranged in rows and columns. Provided that they have the same dimensions
(each matrix has the same number of rows and the same number of columns as the other), two
matrices can be added or subtracted element by element (see conformable matrix). The rule
for matrix multiplication, however, is that two matrices can be multiplied only when the number of
columns in the first equals the number of rows in the second (that is, the inner dimensions are
the same, n for an (m×n)-matrix times an (n×p)-matrix, resulting in an (m×p)-matrix). Even when
two matrices have dimensions allowing them to be multiplied in either order, the results need not
be the same. That is, matrix multiplication is not, in general, commutative. Any matrix can
be multiplied element-wise by a scalar from its associated field.

Here, we created different functions using c to perform all the matrix operation.

2.CONCEPT OF THE PROGRAM

2a. FOR MATRIX ADDITION


To add two matrices, i.e., compute their sum and print it. A user inputs their orders
(number of rows and columns) and the elements of these two matrices.

• Step 1: Take 3 arrays such as first[][], second[][], and sum[][].


• Step 2: Accept the number of rows and columns for the two arrays.
• Step 3: Then, accept elements of these two arrays.
• Step 4: After all, add the corresponding elements of the arrays and
store its elements to the new array and display its elements.
2b. FOR MATRIX SUBTRACTION

• Step 1: Take 3 arrays such as first[][], second[][], and sum[][].


• Step 2: Accept the number of rows and columns for the two arrays.
• Step 3: Then, accept elements of these two arrays.
• Step 4: After all, subtract the corresponding elements of the arrays and
store its elements to the new array and display its elements.

2c. FOR MATRIX MULTIPLICATION

We can add, subtract, multiply and divide 2 matrices. To do so, we are taking input
from the user for row number, column number, first matrix elements and second
matrix elements. Then we are performing multiplication on the matrices entered by
the user.

In matrix multiplication first matrix one row element is multiplied by second matrix all
column elements.

2d. FOR TRANSPOSE OF A MATRIX

Transpose of a matrix is obtained by changing rows to columns and columns to rows. In


other words, transpose of A[][] is obtained by changing A[i][j] to A[j][i]

3. THE PROGRAM CODE


#include<stdio.h>
int main(){

int operation;

printf("\nPLEASE CHOOSE THE OPERATION\n\n");

printf("For Summession of Matrix Press 1\n");

printf("For Substraction of Matrix Press 2\n");

printf("For Transpose of Matrix Press 3\n");

printf("For Multipication of Matrix Press 4\n\n");

printf("ENTER YOUR CHOICE CODE : ");

scanf("%d",&operation);

if(operation==4){

// printf("ok");

int row,col,rowb,colb;

printf("Enter the number of Row of Matrix A : ");

scanf("%d",&row);

printf("Enter the number of Column of Matrix A : ");

scanf("%d",&col);

printf("Enter the number of Row of Matrix B : ");

scanf("%d",&rowb);

printf("Enter the number of Column of Matrix B : ");

scanf("%d",&colb);

float matricsA[row][col];

float matricsB[rowb][colb];
float matricsX[row][colb];

if(col==rowb){

// printf("A %dX%d Matrix and B is %dX%d Matrix\n",row,col,col,row);

// matrics A value input

printf("\nEnter the value of Matrix A\n");

for(int i=0;i<row;i++){

for(int j=0;j<col;j++){

scanf("%f",&matricsA[i][j]);

}printf("\n");

printf("\nEnter the value of Matrix B\n");

for(int i=0;i<rowb;i++){

for(int j=0;j<colb;j++){

scanf("%f",&matricsB[i][j]);

}printf("\n");

for(int i=0;i<row;i++){

for(int j=0;j<colb;j++){

float ans=0;

for(int p=0;p<col;p++){

float ans2;

ans2 = matricsA[i][p]*matricsB[p][j];

ans+=ans2;

matricsX[i][j]=ans;
}

printf("\nProduct Matrix is \n\n");

for(int i=0;i<row;i++){

for(int j=0;j<colb;j++){

printf("%.2f ",matricsX[i][j]);

}printf("\n");

}else{

printf("Please remember if you want to multipication of two matrix . you must keep Column
numbe of Matrix A is Equal to Row number of Matrix B");

}else if(operation==3){

int row,col;

printf("Enter the number of Row of matrix : ");

scanf("%d",&row);

printf("Enter the number of Column of matrix : ");

scanf("%d",&col);

float matricstr[row][col];

float matricstr2[col][row];

// matrics value input

printf("\nEnter the value of matrix A\n");

for(int i=0;i<row;i++){

for(int j=0;j<col;j++){

scanf("%f",&matricstr[i][j]);

}printf("\n");
}

// Transpose Operation

printf("\nTranspose Matrix is - \n");

for(int i=0;i<col;i++){

for(int j=0;j<row;j++){

printf("%.2f ",matricstr[j][i]);

}printf("\n");

else{

int row,col;

printf("Enter the number of Row of matrix : ");

scanf("%d",&row);

printf("Enter the number of Column of matrix : ");

scanf("%d",&col);

float matrics1[row][col];

float matrics2[row][col];

float sum_matrics[row][col];

float sub_matrics[row][col];

// Input of matrics A

printf("\nEnter the value of matrix A\n\n");

for(int i=0;i<row;i++){

for(int j=0;j<col;j++){

scanf("%f",&matrics1[i][j]);
}printf("\n");

// Input of matrics B

printf("\nEnter the value of matrix B\n\n");

for(int i=0;i<row;i++){

for(int j=0;j<col;j++){

scanf("%f",&matrics2[i][j]);

}printf("\n");

// Show matrics A

/*printf("\n\nHere is your Matrics A \n\n");

for(int i=0;i<row;i++){

for(int j=0;j<col;j++){

printf("%.2f ",matrics1[i][j]);

}printf("\n");

}*/

// show matrics B

/*printf("\n\nHere is your Matrics B \n\n");

for(int i=0;i<row;i++){

for(int j=0;j<col;j++){

printf("%.2f ",matrics2[i][j]);

}printf("\n");
}*/

if(operation==1){

// Summession of matrics A and matrics B

for(int i=0;i<row;i++){

for(int j=0;j<col;j++){

sum_matrics[i][j]=matrics1[i][j]+matrics2[i][j];

// Show Summession matrics

printf("\nHere is the Summession Mtarix \n");

for(int i=0;i<row;i++){

for(int j=0;j<col;j++){

printf("%.2f ",sum_matrics[i][j]);

}printf("\n");

}else if(operation==2){

// Substraction of matrics A and matrics B

for(int i=0;i<row;i++){

for(int j=0;j<col;j++){

sub_matrics[i][j]=matrics1[i][j]-matrics2[i][j];

// Show Substraction matrics


printf("\nHere is the Substraction matrics Mtarix \n");

for(int i=0;i<row;i++){

for(int j=0;j<col;j++){

printf("%.2f ",sub_matrics[i][j]);

}printf("\n");

return 0;

4.OUTPUT
5.ADVANTAGES OF USING C TO PERFORM MATRIX OPERATIONS
A. TIME SAVING

B. EASY TO USE

C. CALCULATES AND GIVE PERFECT ANSWERS IN NO TIME

D. HIGHER RATE OF ACCURACY


REFERENCES
https://www.knowprogram.com/c-programming/matrix-operations-in-c/

https://www.geeksforgeeks.org/

You might also like