C programming
C programming

Multiple of Matrix in c

Multiple of Matrix in c

C programming
C programming

Multiple of Matrix in c

 

#include <stdio.h>

// Function to multiply two matrices
void multiplyMatrices(int firstMatrix[10][10], int secondMatrix[10][10], int result[10][10], int rowFirst, int columnFirst, int rowSecond, int columnSecond) {
// Initializing elements of matrix mult to 0
for(int i = 0; i < rowFirst; ++i) {
for(int j = 0; j < columnSecond; ++j) {
result[i][j] = 0;
}
}

// Multiplying firstMatrix and secondMatrix and storing the result in result
for(int i = 0; i < rowFirst; ++i) {
for(int j = 0; j < columnSecond; ++j) {
for(int k = 0; k < columnFirst; ++k) {
result[i][j] += firstMatrix[i][k] * secondMatrix[k][j];
}
}
}
}

// Function to display a matrix
void displayMatrix(int matrix[10][10], int row, int column) {
for(int i = 0; i < row; ++i) {
for(int j = 0; j < column; ++j) {
printf(“%d\t”, matrix[i][j]);
}
printf(“\n”);
}
}

int main() {
int firstMatrix[10][10], secondMatrix[10][10], result[10][10], rowFirst, columnFirst, rowSecond, columnSecond;

printf(“Enter rows and columns for the first matrix: “);
scanf(“%d %d”, &rowFirst, &columnFirst);

printf(“Enter elements of the first matrix:\n”);
for(int i = 0; i < rowFirst; ++i) {
for(int j = 0; j < columnFirst; ++j) {
scanf(“%d”, &firstMatrix[i][j]);
}
}

printf(“Enter rows and columns for the second matrix: “);
scanf(“%d %d”, &rowSecond, &columnSecond);

printf(“Enter elements of the second matrix:\n”);
for(int i = 0; i < rowSecond; ++i) {
for(int j = 0; j < columnSecond; ++j) {
scanf(“%d”, &secondMatrix[i][j]);
}
}

// Check if multiplication is possible
if (columnFirst != rowSecond) {
printf(“Error! Multiplication not possible. Number of columns in the first matrix should be equal to the number of rows in the second matrix.\n”);
} else {
// Multiply the two matrices
multiplyMatrices(firstMatrix, secondMatrix, result, rowFirst, columnFirst, rowSecond, columnSecond);

// Display the result
printf(“\nResultant matrix:\n”);
displayMatrix(result, rowFirst, columnSecond);
}

return 0;
}

 

 

 

 


 

Topics Covered :

  • matrix multiplication in c
  • matrix multiplication
  • matrix multiplication c
  • c programming for matrix multiplication
  • matrix programming for interview
  • c programming for gate
  • c programming tutorial
  • c programming lectures
  • c programs on arrays
  • c programming
  • c programming for beginners

 

 


 

Thanks for reading this blog. Hope you get satisfied with the blog and definitely this blog must have valued your time and effort of reading.

Take a time to connect our other digital creations such as Instagram , Facebook and Youtube.

 

πŸ§‘β€πŸ’»πŸ§‘β€πŸ’»Β Social MediaΒ LinksΒ ofΒ Tech DCodeΒ :

πŸ‘‰πŸ»Β YouTube :Β https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
πŸ‘‰πŸ»Β Instagram :Β https://www.instagram.com/thetechdcode/
πŸ‘‰πŸ»Β Facebook Page :Β https://www.facebook.com/thetechdcode
πŸ‘‰πŸ»Β Twitter :Β https://twitter.com/thetechdcode
πŸ‘‰πŸ»Β Telegram Channel :Β https://t.me/thetechdcode
πŸ‘‰πŸ»Β Tech DCode Linktree :Β https://linktr.ee/thetechdcode
πŸ‘‰πŸ»Β My Personal Handles :Β https://linktr.ee/virtualshivamin

πŸ§‘β€πŸ’»πŸ§‘β€πŸ’»Β Social Media LinksΒ ofΒ SHIVAM SINGHΒ (OWNER) :

πŸ‘‰πŸ»Β Instagram :Β https://www.instagram.com/virtualshivamin/
πŸ‘‰πŸ»Β Facebook Page :Β https://www.facebook.com/virtualshivamin/
πŸ‘‰πŸ»Β Twitter :Β https://twitter.com/virtualshivamin/
πŸ‘‰πŸ»Β Personal Linktree :Β https://linktr.ee/virtualshivaminΒ 

matrix multiplication in c,matrix multiplication,matrix multiplication c program,c programming for matrix multiplication,matrix,c programming for interview,c programming for gate,c programming tutorial,c programming lectures,c programs on arrays,c programming,c programming for beginners

Leave a Reply

Your email address will not be published. Required fields are marked *