0% found this document useful (0 votes)
6 views2 pages

Multiply Matrices

The document contains a C program that allows users to input two 3x3 matrices and perform operations such as multiplication and transposition based on user choice. It includes functions for displaying matrices, multiplying them, and transposing them. The program uses a switch statement to execute the chosen operation and displays the result.

Uploaded by

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

Multiply Matrices

The document contains a C program that allows users to input two 3x3 matrices and perform operations such as multiplication and transposition based on user choice. It includes functions for displaying matrices, multiplying them, and transposing them. The program uses a switch statement to execute the chosen operation and displays the result.

Uploaded by

ABC
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Experiment 1:

Write a program to multiply two matrices

Source Code:
#include<stdio.h>
void display(int matrix[3][3]);
void multiply(int matrix1[3][3],int matrix2[3][3]);
void transpose(int matrix1[3][3]);
int main(){
int matrix1[3][3];
int matrix2[3][3];
int n;
printf("Enter 1st Matrix: \n");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
scanf("%d",&matrix1[i][j]);}}
printf("Enter 2nd Matrix: \n");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
scanf("%d",&matrix2[i][j]);}}
printf("Enter choice: \n");
scanf("%d",&n);
switch(n){
case 1: printf("1. Multiplication of two matrices - \n");
multiply(matrix1[3][3],matrix2[3][3]);
break;
case 2: printf("2. Traspose of both the matrices - \n");
transpose(matrix1[3][3]);
transpose(matrix2[3][3]);
break;
default: printf("Wrong choice entered! \n");
break;}
return 0;}
void display(int matrix[3][3]){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
printf("%d ",matrix[i][j]);}
printf("\n");}}
void multiply(int matrix1[3][3],int matrix2[3][3]){
int sum = 0;
int matrix3[3][3];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
sum += matrix1[i][k] * matrix2[k][j];}
matrix3[i][j] = sum;}
sum = 0;}
display(matrix3);}
void transpose(int matrix1[3][3]){
int matrix[3][3];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
matrix[i][j] = matrix1[j][i];}}
display(matrix);}

Output:

You might also like