Resources » Articles/Knowledge Sharing » Computer & Technology

Write a Program To Add,Subtract,Multipications and Traspose of Two Matrices using functions?


Last Updated:   Category: Computer & Technology    
Author: Member Level: Silver    Points: 2


Write a Program To Add,Subtract,Multipications and Traspose of Two Matrices using functions?



Write a Program To Add,Subtract,Multipications and Traspose of Two Matrices using functions?

SOURCE CODE:


#include
#include
void add(int a[3][3],int b[3][3]);
void subt(int c[3][3],int d[3][3]);
void mult(int e[3][3],int f[3][3]);
void tranp(int g[3][3]);

void main()
{
int i,j,opt;
int x[3][3],y[3][3];
clrscr();
printf("This Program is Used to Perform ADDITION,SUBTRACTION,MULTIPICATION and TRANSPOSE on Two Matrices using functions\n");
printf("\n\tEnter The Value Of First Matrix:");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
scanf("%d",&x[i][j]);
}
}

printf("\nEnter The Value Of Second Matrix:");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
scanf("%d",&y[i][j]);
}
}



printf("\nSelect One Option given below:\n");
printf("\n\t1.ADDITION");
printf("\n\t2.SUBTRACTION");
printf("\n\t3.MULTIPICATION");
printf("\n\t4.TRANSPOSE");
printf("\n\tEnter Your value:");
scanf("%d",&opt);

switch(opt)
{
case 1:
add(x,y);
break;
case 2:
subt(x,y);
break;
case 3:
mult(x,y);
break;
case 4:
tranp(x);
break;
}
getch();
}
void add(int a[3][3],int b[3][3])
{
int z[3][3];
int i,j;
printf("\n");
for(i=1;i<=3;i++)
{

for(j=1;j<=3;j++)
{
z[i][j]=a[i][j]+b[i][j];
printf("\t %d",z[i][j]);
}
printf("\n");
}
}







void subt(int c[3][3],int d[3][3])
{
int z[3][3];
int i,j;
printf("\n");
for(i=1;i<=3;i++)
{

for(j=1;j<=3;j++)
{
z[i][j]=c[i][j]-d[i][j];
printf("\t %d",z[i][j]);
}
printf("\n");
}
}

void mult(int e[3][3],int f[3][3])
{
int z[3][3];
int i,j,k;
printf("\n");
for(i=1;i<=3;i++)
{

for(j=1;j<=3;j++)
{
z[i][j]=0;
for(k=1;k<=3;k++)
{

z[i][j]=e[i][k]*f[k][j]+z[i][j];
printf("\t %d",z[i][j]);
}
}
printf("\n");
}
}

void tranp(int g[3][3])
{
int z[3][3];
int i,j;




printf("\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
z[i][j]=g[j][i];
printf("\t %d",z[i][j]);
}
printf("\n");
}
}




OUTPUT

This program is used to perform Addition,Subtraction,Multiplication and Transpose operations on Matrics by using Functions

Enter the value of first Matrix:1 5 7
4 6 9
4 7 9
Enter the value of Second Matrix:2 5 8
1 4 1
3 2 6

Select One option given Below:
1.Addition
2.Subtraction
3.Multiplication
4.Transpose

Enter your choice:1
5 10 15
6 10 2
7 9 15


Did you like this resource? Share it with your friends and show your love!




Responses to "Write a Program To Add,Subtract,Multipications and Traspose of Two Matrices using functions?"
Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Awards & Gifts
    Active Members
    TodayLast 7 Daysmore...

    ISC Technologies, Kochi - India. Copyright © All Rights Reserved.