HEY FRIENDS THIS IS MY EFFROT I'VE MADE A PROGRAM THAT'LL ADD OR SUBTRACT 2 AND THREE DIMENSIONAL MATRICES !!
PLEASE SEND YOUR REVIEWS ABOUT THIS PROGRAM AND SUGGESTION ON WHAT IMPORVEMENTS CAN BE MADE IN IT !! AND ALSO I NEED TO KNOW CAN THIS PROGRAM BE MADE BY ANY OTHER METHOD IF ANY LET ME KNOW THAT'LL BE OF GREAT HELP
#include<stdio.h>
#include<conio.h>
void mat3(int a[3][3]);
void mat2(int b[2][2]);
void output2(int s3[2][2],int s4[2][2]);
void output3(int s1[3][3],int s2[3][3]);
void output2m(int s7[2][2],int s8[2][2]);
void output3m(int s5[3][3],int s6[3][3]);
void line(void);
void main()
{
clrscr();
line();
printf("\xDB M A T R I C E S \xDB\n");
line();
printf("\n\n");
char ch;
printf("Choose the dimensions for matrices\n\n");
printf("b=2*2\nc=3*3\n");
scanf("%c",&ch);
int a2[2][2],a3[3][3];
int b2[2][2],b3[3][3];
switch(ch)
{
case 'b':
printf("Input for 2x2 matrix : \n\n");
for(int i=0;i<2;i++)
for (int j=0;j<2;j++)
{
printf("Enter data for 2x2 matrix >");
scanf("%4d",&a2[i][j]);
printf("\n");
}
for(int p=0;p<2;p++)
for (int q=0;q<2;q++)
{
printf("Enter data for 2nd 2x2 martix >");
scanf("%4d",&b2[p][q]);
printf("\n");
}
printf("\nPress Enter ... \n\n");
printf("Input part over ... Enter to continue \n\n");
getch();
break;
case 'c':
for(int m=0;m<3;m++)
for (int n=0;n<3;n++)
{
printf("Enter data for 3x3 matrix >");
scanf("%4d",&a3[m][n]);
printf("\n");
}
for(int h=0;h<3;h++)
for (int g=0;g<3;g++)
{
printf("Enter data for 2nd 3x3 matrix >");
scanf("%4d",&b3[h][g]);
printf("\n");
}
printf("\nPress Enter ... \n\n");
printf("Input part over ... Enter to continue \n\n");
getch();
break;
default :
printf("Are u Kidding ! \n\n");
getch();
clrscr();
}
clrscr();
int sel;
if (ch=='b')
{
printf("What to do ?....1 for Addition....2 for Substraction\n ");
scanf("%d",&sel);
printf("\n");
if (sel==1)
{
clrscr();
printf(" The Addition Output for 2x2 matrices.... \n");
printf("____________________________________________\n\n\n");
mat2(a2);
printf("\n\n");
printf("\t\t + ");
printf("\n\n\n");
mat2(b2);
printf("\n\n");
printf("\t\t = \n\n\n");
output2(a2,b2);
}
else
if(sel==2)
{
clrscr();
printf(" The Substraction Output for 2x2 matrices.... \n");
printf("____________________________________________\n\n\n");
mat2(a2);
printf("\n\n");
printf("\t\t - ");
printf("\n\n\n");
mat2(b2);
printf("\n\n");
printf("\t\t = \n\n\n");
output2m(a2,b2);
}
}
else
if (ch=='c')
{
printf("What to do ?....1 for Addition....2 for Substraction\n ");
scanf("%d",&sel);
printf("\n");
if (sel==1)
{
clrscr();
printf(" The Addition Output for 3x3 matrices.... \n");
printf("____________________________________________\n\n\n");
mat3(a3);
printf("\n\n");
printf("\t\t + ");
printf("\n\n\n");
mat3(b3);
printf("\n\n");
printf("\t\t = ");
printf("\n\n\n");
output3(a3,b3);
}
else
if (sel==2)
{
clrscr();
printf(" The Substraction Output for 3x3 matrices.... \n");
printf("____________________________________________\n\n\n");
mat3(a3);
printf("\n\n");
printf("\t\t - ");
printf("\n\n\n");
mat3(b3);
printf("\n\n");
printf("\t\t = ");
printf("\n\n\n");
output3m(a3,b3);
}
}
getch();
}
void line(void)
{
int j;
for(j=1;j<=19;j++)
printf("\xDB");
printf("\n");
}
void mat3(int a[3][3])
{
for(int n1=0;n1!=3;n1++)
{
if(n1==0)
{
printf("\t É");
printf("\t\t\t»");
printf("\n");
}
for(int n2=0;n2!=3;n2++)
{
if(n2==0)
printf("\t º ");
printf("%5d ",a[n1][n2]);
if(n2==2)
printf("\tº");
}
printf("\n");
if(n1==2)
{
printf("\t È");
printf("\t\t\t¼");
printf("\n");
}
}
}
void mat2(int b[2][2])
{
for(int x1=0;x1!=2;x1++)
{
if(x1==0)
{
printf("\t É");
printf("\t\t»");
printf("\n");
}
for(int x2=0;x2!=2;x2++)
{
if(x2==0)
printf("\t º ");
printf("%5d ",b[x1][x2]);
if(x2==1)
printf("\tº");
}
printf("\n");
if(x1==1)
{
printf("\t È");
printf("\t\t¼");
printf("\n");
}
}
}
void output3(int s1[3][3],int s2[3][3])
{
int o1[3][3];
for(int ad=0;ad!=3;ad++) // for the output
{
if(ad==0)
{
printf("\t É");
printf("\t\t\t»");
printf("\n");
}
for(int ad1=0;ad1!=3;ad1++)
{
o1[ad][ad1]=s1[ad][ad1]+s2[ad][ad1];
if(ad1==0)
printf("\t º ");
printf("%5d ",o1[ad][ad1]);
if(ad1==2)
printf("\tº");
}
printf("\n");
if(ad==2)
{
printf("\t È");
printf("\t\t\t¼");
printf("\n");
}
}
}
void output2(int s3[2][2],int s4[2][2])
{
int o2[2][2];
for(int l=0;l!=2;l++) // for the output
{
if(l==0)
{
printf("\t É");
printf("\t\t»");
printf("\n");
}
for(int m=0;m!=2;m++)
{
o2[l][m]=s3[l][m]+s4[l][m];
if(m==0)
printf("\t º ");
printf("%5d ",o2[l][m]);
if(m==1)
printf("\tº");
}
printf("\n");
if(l==1)
{
printf("\t È");
printf("\t\t¼");
printf("\n");
}
}
}
void output3m(int s5[3][3],int s6[3][3])
{
int o3[3][3];
for(int v1=0;v1!=3;v1++) // for the output
{
if(v1==0)
{
printf("\t É");
printf("\t\t\t»");
printf("\n");
}
for(int v2=0;v2!=3;v2++)
{
o3[v1][v2]=s5[v1][v2]-s6[v1][v2];
if(v2==0)
printf("\t º ");
printf("%5d ",o3[v1][v2]);
if(v2==2)
printf("\tº");
}
printf("\n");
if(v1==2)
{
printf("\t È");
printf("\t\t\t¼");
printf("\n");
}
}
}
void output2m(int s7[2][2],int s8[2][2])
{
int o4[2][2];
for(int v3=0;v3!=2;v3++) // for the output
{
if(v3==0)
{
printf("\t É");
printf("\t\t»");
printf("\n");
}
for(int v4=0;v4!=2;v4++)
{
o4[v3][v4]=s7[v3][v4]-s8[v3][v4];
if(v4==0)
printf("\t º ");
printf("%5d ",o4[v3][v4]);
if(v4==1)
printf("\tº");
}
printf("\n");
if(v3==1)
{
printf("\t È");
printf("\t\t¼");
printf("\n");
}
}
}