You are on page 1of 4

/* A PROGRAM TO PERFORM

ADDITION,SUBTRACTION,MULTIPLICATION,
TRANSPOSE OF 2-D ARRAY USING FUNCTIONS: BY 2308219 */
#include<stdio.h>
#include<conio.h>
void add(int*,int*);
void sub(int*,int*);
void mul(int*,int*);
void tran(int*);
int x,y,i,j,k,l;
char ch;
int a[10][10],b[10][10],c[10][10]={0};
void main()
{
extern int i,j,k,l,x,y;
printf("enter the order of matrix A");
scanf("%d %d",&i,&j);
printf("enter the elements of matrix A\n");
for(x=0;x<i;x++)
{
for(y=0;y<j;y++)
{
scanf("%d",&a[x][y]);
}
}
printf("enter the order of matrix B");
scanf("%d %d",&k,&l);
printf("enter the elements of matrix of B\n");
for(x=0;x<k;x++)
{
for(y=0;y<l;y++)
{
scanf("%d",&b[x][y]);
}
}
printf("What do you want to perform?\n");
printf("enter 'a' for addition\n");
printf("enter 's' for substraction\n");
printf("enter 'm' for multiplication\n");
printf("enter 't' for transpose\n");
fflush(stdin);
scanf("%c",&ch);

switch(ch)
{
case 'a':
if(i==k&&j==l)
add(a,b);
else
printf("addition is not possible");
getch();
exit();
case's':
if(i==k&&j==l)
sub(a,b);
else
printf("substraction is not possible");
getch();
exit();
case'm':
if(j==k)
mul(a,b);
else
printf("Multiplication is not possible");
getch();
exit();
case't':
tran(a);
getch();
exit();
default:
printf("Wrong key is pressed");
getch();
exit();
}
}
void add(int*p,int*q)
{for(x=0;x<3;x++)
for(y=0;y<3;y++) {
c[x][y]=b[x][y]+a[x][y];
}
printf("Addition of matrix is C=\n");
for(x=0;x<i;x++)

{
for(y=0;y<j;y++)
{
printf("%d\t",c[x][y]);
}
printf("\n");
}
}
void sub(int*p,int*q)
{
printf("substraction of given matrix is C=\n");
for(x=0;x<i;x++)
{
for(y=0;y<j;y++)
{
c[x][y]=a[x][y]-b[x][y];
printf("%d\t",c[x][y]);
}
printf("\n");
}
}
int z;
void mul(int*p,int*q)
{printf("Multiplication of given matrix is C=\n");/*
int c[9][9]=0;*/
for(x=0;x<i;x++)
{
for(y=0;y<l;y++)
{
for(z=0;z<j;z++)
c[x][y]=c[x][y]+(a[x][z]*b[z][y]);
printf("%d",c[x][y]);
printf("\t");
}
printf("\n");
}
}
void tran(int*p)
{
for(x=0;x<i;x++)

for(y=0;y<j;y++)
{
c[x][y]=a[y][x];
printf("%d\t",c[x][y]);
}
printf("\n");
}

You might also like