/*****************************************************************
* File : addmat.c
* Purpose : Compute the Addition of TWO matrices and Display the results.
* Author : Nanda Kishor K N
* Mail Id : knnkishor@yahoo.com, nandakishorkn@rediffmail.com
* Website : www.c4swimmers.net ( WEB MASTER )
* Group : c4swimmers@yahoogroups.com ( GROUP OWNER )
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License,or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*****************************************************************/
#include<stdio.h>
/*
Name : main()
Purpose : This is the main function that accepts the elements for TWO Matrices and
display the result. This does not call any other function.
Parameter : None
*/
int main()
{
// Variable Declarations & Initialization
// Naming conventions are used like all integer variables should begin with 'i'
int iRow,iCol,iIdx,jIdx,iMat1[10][10],iMat2[10][10],iMatRes[10][10];
printf("Enter row & column : ");
scanf("%d,%d",&iRow,&iCol);
printf("\nEnter %d elements for matrix A\n",iRow * iCol);
// Accept the elements for Matrix1
for (iIdx = 1; iIdx <= iRow; iIdx++)
{
for (jIdx = 1; jIdx <= iCol; jIdx++)
scanf("%d",&iMat1[iIdx][jIdx]);
}
// Accept the elements for Matrix2
printf("\nEnter %d elements for matrix B\n",iRow * iCol);
for (iIdx = 1; iIdx <= iRow; iIdx++)
{
for (jIdx = 1; jIdx <= iCol; jIdx++)
scanf("%d",&iMat2[iIdx][jIdx]);
}
// Compute the Addition of 2 Matrices
for (iIdx = 1; iIdx <= iRow; iIdx++)
{
for (jIdx = 1; jIdx <= iCol; jIdx++)
iMatRes[iIdx][jIdx] = iMat1[iIdx][jIdx] + iMat2[iIdx][jIdx];
}
// Display the result
printf("\nMatrix C = Matrix A + Matrix B\n");
for (iIdx = 1; iIdx <= iRow; iIdx++)
{
for (jIdx = 1; jIdx <= iCol; jIdx++)
printf("%d\t",iMatRes[iIdx][jIdx]);
printf("\n");
}
return 0;
} // End of Program
|