1// Aim: Program to perform Menu Driven operations on matrices (Addition, Multiplication, Transpose).
2#include<stdio.h>
3void main(){
4 int a[30][30],b[30][30],sum[30][30],pro[30][30],trans[30][30],r1,c1,r2,c2,i,j,k,ch=0,x;
5 while(ch!=4){
6
7 printf("\nENTER THE OPERATION TO PERFORM \n1.addition\n2.multiplication\n3.transpose\n4.EXIT");
8 printf("\nEnter the operation to perform :");
9 scanf("%d",&x);
10
11 switch(x){
12 case 1 :
13 printf("Enter the order of the 1st matrix :");
14 scanf("%d %d",&r1,&c1);
15 printf("Enter the order of the 2nd matrix :");
16 scanf("%d %d",&r2,&c2);
17 printf("enter the elements of the 1st matrix :");
18 for(i=0;i<r1;i++){
19 for(j=0;j<c1;j++){
20 scanf("%d",&a[i][j]);}
21 }
22 printf("enter the elements of 2nd matrix :");
23 for(i=0;i<r2;i++){
24 for(j=0;j<c2;j++){
25 scanf("%d",&b[i][j]);}
26 }
27 printf("the first matrix :-\n");
28 for(i=0;i<r1;i++){
29 for(j=0;j<c1;j++){
30 printf("\t %d",a[i][j]);}
31 printf("\n");
32 }
33 printf("the second matrix :-\n");
34 for(i=0;i<r2;i++){
35 for(j=0;j<c2;j++){
36 printf("\t %d",b[i][j]);}
37 printf("\n");
38 }
39 printf("the sum of the matrix\n");
40 for(i=0;i<r1;i++){
41 for(j=0;j<c1;j++){
42 sum[i][j]=a[i][j]+b[i][j];
43 printf("\t %d",sum[i][j]);}
44 printf("\n");
45 }
46 break;
47
48 case 2 :
49 printf("Enter the order of the 1st matrix :");
50 scanf("%d %d",&r1,&c1);
51 printf("Enter the order of the 2nd matrix :");
52 scanf("%d %d",&r2,&c2);
53 printf("enter the elements of the 1st matrix :");
54 for(i=0;i<r1;i++){
55 for(j=0;j<c1;j++){
56 scanf("%d",&a[i][j]);}
57 }
58 printf("enter the elements of 2nd matrix :");
59 for(i=0;i<r2;i++){
60 for(j=0;j<c2;j++){
61 scanf("%d",&b[i][j]);}
62 }
63 printf("the first matrix :-\n");
64 for(i=0;i<r1;i++){
65 for(j=0;j<c1;j++){
66 printf("\t %d",b[i][j]);}
67 printf("\n");
68 }
69 printf("the second matrix :-\n");
70 for(i=0;i<r2;i++){
71 for(j=0;j<c2;j++){
72 printf("\t %d",b[i][j]);}
73 printf("\n");
74 }
75 for(i=0;i<r1;i++){
76 for(j=0;j<c2;j++){
77 for(k=0;k<r1;k++){
78 pro[i][j]=a[i][k]*b[k][j];
79 }}}
80 printf("product :-\n");
81 for(i=0;i<r1;i++){
82 for(j=0;j<c1;j++){
83 printf("\t %d",pro[i][j]);
84 }
85 printf("\n");}
86 break;
87
88 case 3 :
89 printf("Enter the order of the matrix :");
90 scanf("%d %d",&r1,&c1);
91 printf("enter the elements of the matrix :");
92 for(i=0;i<r1;i++){
93 for(j=0;j<c1;j++){
94 scanf("%d",&a[i][j]);}
95 }
96 printf("the matrix :-\n");
97 for(i=0;i<r1;i++){
98 for(j=0;j<c1;j++){
99 printf("\t %d",a[i][j]);}
100 printf("\n");
101 }
102 printf("the transpose matrix :-\n");
103 for(i=0;i<r1;i++){
104 for(j=0;j<c1;j++){
105 trans[i][j]=a[j][i];
106 printf("\t %d",trans[i][j]);}
107 printf("\n");
108 }
109 break;
110 case 4 :
111 ch=4;
112 printf("THANK YOU");
113 break;
114
115 }
116}
117}
118
119