Blog Archive

Sunday, August 29, 2010

Program for matrix addtion using function.

/*
Program for matrix addtion using function.
*/
#include<conio.h>
#include<stdio.h>
void matrixadd(int*,int*,int,int);
int main()
{
int matrix1[5][5]={{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11,12,13,14,15},
{16,17,18,19,20},
{21,22,23,24,25}
};
int matrix2[5][5]={{10,20,30,40,50},
{2, 7, 5, 3, 1},
{1, 8, 3, 4, 5},
{6,17,18,19,20},
{23,2, 3, 4, 5}
};
int counter1=0,counter2=0;
clrscr();
matrixadd(matrix1,matrix2,5,5);
for(counter1=0; counter1<5; counter1++)
{
for(counter2=0; counter2<5; counter2++)
{
printf("%d ",matrix1[counter1][counter2]);
}
printf("\n");
}
return 0;
}

void matrixadd(int *mat1,int *mat2,int x,int y)
{
int row=0,col=0;

for(row=0; row{
for(col=0; col {
mat1[row*y+col]+=mat2[row*y+col];
}
}
}

No comments:

Post a Comment