SlideShare a Scribd company logo
Transpose Matrix
1. Get the number of rows and columns of the matrix.
2. For getting Matrix 1
i. Create an empty list a for the first matrix.
ii. Prompt the user to enter the elements of matrix 1.
iii. Append each element to the list a.
3. Initialize Result Matrix:
i. Create an empty list re for the result matrix.
ii. Initialize this matrix with zeros.
4. Perform Matrix Transposition:
i. Iterate through each element of the matrix.
ii. Transpose the elements by swapping indices: re[i][j] = a[j][i].
5. Print the resultant matrix re.
21. Transpose of a matrix
print("Matrix Transpose")
r,c = map(int, input("enter the row and column of matrix-->").split())
a=[]
print("Enter",r*c," elements of matrix1")
for i in range(0,r):
a1=[]
for j in range(0,c):
e=int(input())
a1.append(e)
a.append(a1)
re=[]
for i in range(0,r):
a1=[]
for j in range(0,c):
a1.append(0)
re.append(a1)
for i in range(0,r):
for j in range(0,c):
re[i][j]=a[j][i]
print ("The resultant matrix is")
print (re)
Output:
Matrix Transpose
enter the row and
column of matrix-->2
2
Enter 4 elements of
matrix1
1
2
3
4
The resultant matrix is
[[1, 3], [2, 4]]
Matrix Addition:
1. Get the number of rows and columns of the matrices.
2. For getting Matrix 1
i. Create an empty list a for the first matrix.
ii. Prompt the user to enter the elements of matrix 1.
iii. Append each element to the list a.
3. For getting Matrix 2
i. Create an empty list b for the second matrix.
ii. Prompt the user to enter the elements of matrix 2.
iii. Append each element to the list b.
4. Initialize Result Matrix:
i. Create an empty list re for the result matrix.
ii. Initialize this matrix with zeros.
5. Perform Matrix Addition:
i. Iterate through each element of the matrices.
ii. Add the corresponding elements of matrix 1 and matrix 2.
iii. Store the result in the corresponding position in the result matrix re.
6. Print the resultant matrix re.
Addition of matrix
print("Matrix Addition")
r,c = map(int, input("enter the row and column of matrix-->").split())
a=[]
print("Enter",r*c," elements of matrix1")
for i in range(0,r):
a1=[]
for j in range(0,c):
e=int(input())
a1.append(e)
a.append(a1)
b=[]
print("Enter",r*c," elements of matrix2")
for i in range(0,r):
a1=[]
for j in range(0,c):
e=int(input())
a1.append(e)
b.append(a1)
re=[]
for i in range(0,r):
a1=[]
for j in range(0,c):
a1.append(0)
re.append(a1)
for i in range(0,r):
for j in range(0,c):
re[i][j]=a[i][j]+b[i][j]
print ("The resultant matrix is")
print (re)
Output
Matrix Addition
enter the row and
column of matrix-->2
2
Enter 4 elements of
matrix1
1
2
3
4
Enter 4 elements of
matrix2
1
2
3
4
The resultant matrix is
[[2, 4], [6, 8]]
Matrix Subtraction:
1. Get the number of rows and columns of the matrices.
2. For getting Matrix 1
i. Create an empty list a for the first matrix.
ii. Prompt the user to enter the elements of matrix 1.
iii. Append each element to the list a.
3. For getting Matrix 2
i. Create an empty list b for the second matrix.
ii. Prompt the user to enter the elements of matrix 2.
iii. Append each element to the list b.
4. Initialize Result Matrix:
i. Create an empty list re for the result matrix.
ii. Initialize this matrix with zeros.
5. Perform Subtraction Addition:
i. Iterate through each element of the matrices.
ii. Subtract the corresponding elements of matrix 1 and matrix 2.
iii. Store the result in the corresponding position in the result matrix re.
6. Print the resultant matrix re.
Subtraction of matrix
print("Matrix Subtraction")
r,c = map(int, input("enter the row and column of matrix-->").split())
a=[]
print("Enter",r*c," elements of matrix1")
for i in range(0,r):
a1=[]
for j in range(0,c):
e=int(input())
a1.append(e)
a.append(a1)
b=[]
print("Enter",r*c," elements of matrix2")
for i in range(0,r):
a1=[]
for j in range(0,c):
e=int(input())
a1.append(e)
b.append(a1)
re=[]
for i in range(0,r):
a1=[]
for j in range(0,c):
a1.append(0)
re.append(a1)
for i in range(0,r):
for j in range(0,c):
re[i][j]=a[i][j]+b[i][j]
print ("The resultant matrix is")
print (re)
Output
Matrix Subtraction
enter the row and
column of matrix-->2
2
Enter 4 elements of
matrix1
1
2
3
4
Enter 4 elements of
matrix2
4
3
2
1
The resultant matrix is
[[-3, -1], [1, 3]]
Matrix Multiplication:
1. Get the number of rows and columns of the matrices.
2. For getting Matrix 1
i. Create an empty list a for the first matrix.
ii. Prompt the user to enter the elements of matrix 1.
iii. Append each element to the list a.
3. For getting Matrix 2
i. Create an empty list b for the second matrix.
ii. Prompt the user to enter the elements of matrix 2.
iii. Append each element to the list b.
4. Initialize Result Matrix:
i. Create an empty list re for the result matrix.
ii. Initialize this matrix with zeros.
5. Perform Matrix Multiplication:
i. Iterate through each element of the matrices.
ii. For each element in re[i][j], calculate the sum of the products of the corresponding
elements in matrix 1 and matrix 2.
iii. Store the result in the corresponding position in the result matrix re.
6. Print the resultant matrix re.
Multiplication of matrix
print("Matrix Multiplication")
r,c = map(int, input("enter the row and column of matrix-->").split(" "))
a=[]
print("Enter",r*c," elements of matrix1")
for i in range(0,r):
a1=[]
for j in range(0,c):
e=int(input())
a1.append(e)
a.append(a1)
b=[]
print("Enter",r*c," elements of matrix2")
for i in range(0,r):
a1=[]
for j in range(0,c):
e=int(input())
a1.append(e)
b.append(a1)
re=[]
for i in range(0,r):
a1=[]
for j in range(0,c):
a1.append(0)
re.append(a1)
for i in range(0,r):
for j in range(0,c):
for k in range(0,c):
re[i][j]+=a[i][k]*b[k][j]
print ("The resultant matrix is")
print (re)
Output
Matrix Multiplication
enter the row and
column of matrix-->2
2
Enter 4 elements of
matrix1
1
2
3
4
Enter 4 elements of
matrix2
4
3
2
1
The resultant matrix is

More Related Content

PPTX
Two dimensional arrays
PDF
Multi dimensional array
PDF
Introduction to Data Science With R Lab Record
PPTX
Python programming workshop session 3
PPT
Array 31.8.2020 updated
PDF
2D array
PDF
Lecture4
PPTX
arrays.pptx
Two dimensional arrays
Multi dimensional array
Introduction to Data Science With R Lab Record
Python programming workshop session 3
Array 31.8.2020 updated
2D array
Lecture4
arrays.pptx

Similar to Matrix Programs in C with steps and sollutions (20)

PDF
Data Structure & Algorithms - Matrix Multiplication
PDF
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
PPTX
MATLAB - Arrays and Matrices
PPTX
unit-2-dsa.pptx
PPTX
Introduction to matlab lecture 2 of 4
PDF
import java.util.LinkedList; import java.util.Random; import jav.pdf
PDF
Matrices & Determinants.pdf
PDF
Can you help me by answering this- The following function defined in c.pdf
PDF
Programs in array using SWIFT
PPTX
Arrays 2d Arrays 2d Arrays 2d Arrrays 2d
PPTX
ARRAY OPERATIONS.pptx
PDF
Arrays in python
PPT
Java: Introduction to Arrays
PPTX
Matrix introduction jsssssssssssssssssjsj
PPTX
class-1ggggggggggggggggggggggggggg7.pptx
PDF
Python programming : Arrays
PDF
computer Science project.pdf
PDF
Unit-5-Part1 Array in Python programming.pdf
Data Structure & Algorithms - Matrix Multiplication
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
MATLAB - Arrays and Matrices
unit-2-dsa.pptx
Introduction to matlab lecture 2 of 4
import java.util.LinkedList; import java.util.Random; import jav.pdf
Matrices & Determinants.pdf
Can you help me by answering this- The following function defined in c.pdf
Programs in array using SWIFT
Arrays 2d Arrays 2d Arrays 2d Arrrays 2d
ARRAY OPERATIONS.pptx
Arrays in python
Java: Introduction to Arrays
Matrix introduction jsssssssssssssssssjsj
class-1ggggggggggggggggggggggggggg7.pptx
Python programming : Arrays
computer Science project.pdf
Unit-5-Part1 Array in Python programming.pdf
Ad

More from ssuser80a5aa (8)

PDF
8.3. Advance III - algm to pgm 1.pdfAdvance I - Seminar.pdf
PDF
8.4. Advance III - algm to pgm 2.pdfAdvance I - Seminar.pdf
DOCX
List & Tuple questions with seperate questions
DOCX
Shortened Linked List in C programming easy to learn for exam
DOCX
C Programming End Sem Question Set Question Paper with mark allocation
PPTX
Data Structures unit I just look to learn the contents
PPTX
Data Structures unit I just look to learn the contents
PPTX
Data Structures unit I just look to learn the contents
8.3. Advance III - algm to pgm 1.pdfAdvance I - Seminar.pdf
8.4. Advance III - algm to pgm 2.pdfAdvance I - Seminar.pdf
List & Tuple questions with seperate questions
Shortened Linked List in C programming easy to learn for exam
C Programming End Sem Question Set Question Paper with mark allocation
Data Structures unit I just look to learn the contents
Data Structures unit I just look to learn the contents
Data Structures unit I just look to learn the contents
Ad

Recently uploaded (20)

PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
Software Engineering and software moduleing
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PPTX
communication and presentation skills 01
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
CyberSecurity Mobile and Wireless Devices
PPTX
Feature types and data preprocessing steps
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
Fundamentals of Mechanical Engineering.pptx
PPT
Total quality management ppt for engineering students
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
Soil Improvement Techniques Note - Rabbi
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Software Engineering and software moduleing
August -2025_Top10 Read_Articles_ijait.pdf
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
communication and presentation skills 01
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
CyberSecurity Mobile and Wireless Devices
Feature types and data preprocessing steps
Management Information system : MIS-e-Business Systems.pptx
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Fundamentals of Mechanical Engineering.pptx
Total quality management ppt for engineering students
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
Module 8- Technological and Communication Skills.pptx
Soil Improvement Techniques Note - Rabbi
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT

Matrix Programs in C with steps and sollutions

  • 1. Transpose Matrix 1. Get the number of rows and columns of the matrix. 2. For getting Matrix 1 i. Create an empty list a for the first matrix. ii. Prompt the user to enter the elements of matrix 1. iii. Append each element to the list a. 3. Initialize Result Matrix: i. Create an empty list re for the result matrix. ii. Initialize this matrix with zeros. 4. Perform Matrix Transposition: i. Iterate through each element of the matrix. ii. Transpose the elements by swapping indices: re[i][j] = a[j][i]. 5. Print the resultant matrix re. 21. Transpose of a matrix print("Matrix Transpose") r,c = map(int, input("enter the row and column of matrix-->").split()) a=[] print("Enter",r*c," elements of matrix1") for i in range(0,r): a1=[] for j in range(0,c): e=int(input()) a1.append(e) a.append(a1) re=[] for i in range(0,r): a1=[] for j in range(0,c): a1.append(0) re.append(a1) for i in range(0,r): for j in range(0,c): re[i][j]=a[j][i] print ("The resultant matrix is") print (re) Output: Matrix Transpose enter the row and column of matrix-->2 2 Enter 4 elements of matrix1 1 2 3 4 The resultant matrix is [[1, 3], [2, 4]] Matrix Addition: 1. Get the number of rows and columns of the matrices. 2. For getting Matrix 1 i. Create an empty list a for the first matrix. ii. Prompt the user to enter the elements of matrix 1. iii. Append each element to the list a. 3. For getting Matrix 2 i. Create an empty list b for the second matrix. ii. Prompt the user to enter the elements of matrix 2. iii. Append each element to the list b. 4. Initialize Result Matrix: i. Create an empty list re for the result matrix. ii. Initialize this matrix with zeros. 5. Perform Matrix Addition:
  • 2. i. Iterate through each element of the matrices. ii. Add the corresponding elements of matrix 1 and matrix 2. iii. Store the result in the corresponding position in the result matrix re. 6. Print the resultant matrix re. Addition of matrix print("Matrix Addition") r,c = map(int, input("enter the row and column of matrix-->").split()) a=[] print("Enter",r*c," elements of matrix1") for i in range(0,r): a1=[] for j in range(0,c): e=int(input()) a1.append(e) a.append(a1) b=[] print("Enter",r*c," elements of matrix2") for i in range(0,r): a1=[] for j in range(0,c): e=int(input()) a1.append(e) b.append(a1) re=[] for i in range(0,r): a1=[] for j in range(0,c): a1.append(0) re.append(a1) for i in range(0,r): for j in range(0,c): re[i][j]=a[i][j]+b[i][j] print ("The resultant matrix is") print (re) Output Matrix Addition enter the row and column of matrix-->2 2 Enter 4 elements of matrix1 1 2 3 4 Enter 4 elements of matrix2 1 2 3 4 The resultant matrix is [[2, 4], [6, 8]] Matrix Subtraction: 1. Get the number of rows and columns of the matrices. 2. For getting Matrix 1 i. Create an empty list a for the first matrix. ii. Prompt the user to enter the elements of matrix 1. iii. Append each element to the list a. 3. For getting Matrix 2 i. Create an empty list b for the second matrix. ii. Prompt the user to enter the elements of matrix 2. iii. Append each element to the list b. 4. Initialize Result Matrix: i. Create an empty list re for the result matrix. ii. Initialize this matrix with zeros. 5. Perform Subtraction Addition: i. Iterate through each element of the matrices.
  • 3. ii. Subtract the corresponding elements of matrix 1 and matrix 2. iii. Store the result in the corresponding position in the result matrix re. 6. Print the resultant matrix re. Subtraction of matrix print("Matrix Subtraction") r,c = map(int, input("enter the row and column of matrix-->").split()) a=[] print("Enter",r*c," elements of matrix1") for i in range(0,r): a1=[] for j in range(0,c): e=int(input()) a1.append(e) a.append(a1) b=[] print("Enter",r*c," elements of matrix2") for i in range(0,r): a1=[] for j in range(0,c): e=int(input()) a1.append(e) b.append(a1) re=[] for i in range(0,r): a1=[] for j in range(0,c): a1.append(0) re.append(a1) for i in range(0,r): for j in range(0,c): re[i][j]=a[i][j]+b[i][j] print ("The resultant matrix is") print (re) Output Matrix Subtraction enter the row and column of matrix-->2 2 Enter 4 elements of matrix1 1 2 3 4 Enter 4 elements of matrix2 4 3 2 1 The resultant matrix is [[-3, -1], [1, 3]] Matrix Multiplication: 1. Get the number of rows and columns of the matrices. 2. For getting Matrix 1 i. Create an empty list a for the first matrix. ii. Prompt the user to enter the elements of matrix 1. iii. Append each element to the list a. 3. For getting Matrix 2 i. Create an empty list b for the second matrix. ii. Prompt the user to enter the elements of matrix 2. iii. Append each element to the list b. 4. Initialize Result Matrix: i. Create an empty list re for the result matrix. ii. Initialize this matrix with zeros. 5. Perform Matrix Multiplication: i. Iterate through each element of the matrices.
  • 4. ii. For each element in re[i][j], calculate the sum of the products of the corresponding elements in matrix 1 and matrix 2. iii. Store the result in the corresponding position in the result matrix re. 6. Print the resultant matrix re. Multiplication of matrix print("Matrix Multiplication") r,c = map(int, input("enter the row and column of matrix-->").split(" ")) a=[] print("Enter",r*c," elements of matrix1") for i in range(0,r): a1=[] for j in range(0,c): e=int(input()) a1.append(e) a.append(a1) b=[] print("Enter",r*c," elements of matrix2") for i in range(0,r): a1=[] for j in range(0,c): e=int(input()) a1.append(e) b.append(a1) re=[] for i in range(0,r): a1=[] for j in range(0,c): a1.append(0) re.append(a1) for i in range(0,r): for j in range(0,c): for k in range(0,c): re[i][j]+=a[i][k]*b[k][j] print ("The resultant matrix is") print (re) Output Matrix Multiplication enter the row and column of matrix-->2 2 Enter 4 elements of matrix1 1 2 3 4 Enter 4 elements of matrix2 4 3 2 1 The resultant matrix is