You Are The Visitor Number

Saturday, May 17, 2008

/* Program to add two matrices */

Here is the program The student find most tough!!! Why?? Because it so lenghty. Again tough?? because it uses so many for loops many times first for filling of first matrices showing filled matrices & also one loop shows output matrix…

If you understand this program you can do anything in matrix algebra But you should also know mathematics!!! J
J
J
J


 

This program also helps you to understand the concept of arrays.. Now you try substraction by your own skills… till then wait for multiplication of matrices one>>>>


 

/* Program to add two matrices */

/*"Author: Mitochondria Technologies Inc.(Regd.)"*/


 

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,m,n,a[5][5],b[5][5],c[5][5];

clrscr();

printf("enter the no. of rows n columns:");

scanf("%d %d",&n,&m);

printf("enter matrix A:");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

scanf("%d",&a[i][j]);

}

}

printf("\nMatrix A is inserted.");

printf("\n");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

printf("%d",a[i][j]);

}

printf("\n");

}

printf("\nEnter matrix B:");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

scanf("%d",&b[i][j]);

}

}

printf("\nMatrix B is inserted.");

printf("\n");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

printf("%d",b[i][j]);

}

printf("\n");

}

printf("The Addition of two matrices is:\n");

for(i=0;i<n;i++)

{

for(j=0;j<m;j++)

{

c[i][j]=a[i][j]+b[i][j];

}

}

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

printf("%d\t",c[i][j]);

}

printf("\n");

}

getch();

}


 


 


 

No comments: