You are on page 1of 8

RAGHU INSTITUTE OF TECHNOLOGY

SPECIFICATION :
( 6) (b) C Program to input two matrices , check the compatibility and perform addition and
multiplication.
ALGORITHM:
STEP-1: Start.
STEP-2: Declare m,n,p,q,c,d,f[10][10],s[10][10],sum[10][10].
STEP-4: Check the conditions .
4.1:Check the compatibility through the condition(m==p&&n==q) and print the
statements .
4.2: Enter the matrices through the loops and read the values.
4.3: Compute:
sum[c][d]

f[c][d]+s[c][d]

STEP-6: Stop.

FLOWCHART:

RAGHU INSTITUTE OF TECHNOLOGY

START

DECLARE m,n,p,q,f[10][10],s[10][10],cum[10][10]

FALSE

(m==p&
&n==q)
TRUE

FALSE
for c in steps of 1 do where c<m
TRUE

STOP
FALSE

TRUE

FALSE

TRUE

FALSE

RAGHU INSTITUTE OF TECHNOLOGY

FALSE
for c in steps of 1 do where c<m
TRUE

FALSE
for d in steps of 1 do where d<n
TRUE

sum[c][d]=f[c][d]+s[c][d]

FALSE
for c in steps of 1 do where c <m
TRUE

for d in steps of 1 do where d<n

FALSE
TRUE
SUM OF MATRICES IS:

STOP

RAGHU INSTITUTE OF TECHNOLOGY

PROGRAM
/* C Program for Addition of two Matrices and to check their compatibility */

Program name:
/* Done By : C-Faculty

// wk6b.c
Dated: 15/10/2013*/

#include<stdio.h>
#include<curses.h>
int main()
{
int m,n,p,q,c,d,f[10][10],s[10][10];
clear();
printf(enter rows and columns for both the matrices );
scanf(%d%d%d%d,&m,&n,&p,&q);
if(m==p&&n==q)
{
}
else
{
}
printf(enter elements into first matrix);
for(c=0;c<m;c++)
{
for(d=0;d<n;d++)

RAGHU INSTITUTE OF TECHNOLOGY

{
scanf(%d,&f[c][d]);
}
}
printf(enter the elements into the second matrix);
for(c=0;c<m;c++)
{
for(d=0;d<n;d++)
{
scanf(%d,&s[c][d]);
}
}
for(c=0;c<m;c++)
{
for(d=0;d<n;d++)
{
sum[c][d]=f[c][d]+s[c][d];
}
}
printf(sum of matrices is:);
for(c=0;c<m;c++)
{
for(d=0;d<n;d++)
{
printf(%d,sum[c][d]);
Department of Computer Science & Engg

RAGHU INSTITUTE OF TECHNOLOGY

}
}
return(0);
}
PROCEDURE FOR EXECUTING THE PROGRAM:
Step 1: After typing the program, press ESC button+shift+: and then type wq(to save the
program and quit)
Step 2: Now compile the program by using the following command
cc wk6b.c lcurses -lm
Step 3: Now go for running the program by using the command
./a.out

EXPECTED I/P AND O/P:

Output (1)
enter rows and columns for both the matrices
2222
enter elements into first matrix
12
34
enter the elements into the second matrix
12
34
sum of matrices is:
24
68
Output (2)
enter rows and columns for both the matrices
2332

RAGHU INSTITUTE OF TECHNOLOGY

Original Output :
Output (1)
enter rows and columns for both the matrices
2222
enter elements into first matrix
12
34
enter the elements into the second matrix
12
34
sum of matrices is:
24
68
Output (2)
enter rows and columns for both the matrices
2222
enter elements into first matrix
72
51
enter the elements into the second matrix
12
34
sum of matrices is:
84
85
VIVA VOCE QUESATIONS:
1) What is condition that is required to perform matrix addition?
Ans: To perform matrix addition, the two matrices must have the equal size i.e. equal number of
rows and columns.
2) What is condition that is required to perform matrix multiplication?
Ans: To perform matrix multiplication we have to check for compatibility condition i.e. the
number of columns in the first matrix must be equal with the number of rows in the second
matrix. Otherwise matrix multiplication cant be performed.
3) What is a function?
A function is a self-contained block of code that performs a particular task.

4) What is a main ()?

Main is a specially recognized function in C. Every program must have a main function to
indicate where the program has to begin its execution.
--xXx--