Wednesday, 10 September 2014

Addition of Two Matrices in C Langauge with Example

C program for addition of 2 matrices using arrays concept. This source code is all about matrices and their calculation. This is based on 2×2 matrix addition. So that, you have to enter totally 8 inputs for the 2 matrices. And the output will produce an another matrix. Source code of this C tutorial is given below.


This C program is used to adding the two matrix methods. An addition operation will be in a row and column wise for the matrix program. It is also a simple code like mathematical matrix. For example,

First Matrix value:-

1  2
3 4

Second matrix value:-

5  6
2  1

Then output of the Matrix addition is:-

09  08
23  22

Q: Write a C program to calculate the addition of two matrices using Arrays.

//Header files
#define MAX 5
void main()
//Program variables
 int ma1[MAX][MAX],ma2[MAX][MAX],ma3[MAX][MAX];
 int i,j;
 int a,b,a1,b1;
 printf("Enter the row and column of a matrix"); //Display function
 scanf("%d%d",&a,&b); //Getting input function
 printf("Enter the value of first matrix");
 for(j=0;j<=(b-1);b++)//Looping statement
   for(i=0;i<=(a-1);i++)//Nested for loop
 printf("enter the size of second matrix");
  if(b!=a1)//Conditional statement
   printf("Size of second matrix is not compatible");
     printf("Enter value of second matrix");
        printf("Addition  of matrix is=%d ",ma3[i][j]);

No comments:

Post a comment

Note: only a member of this blog may post a comment.