66 views

Uploaded by prasad9440024661

Any Doubts , Contact Resource Persons:
Mrs S Radhika, IT Dept .
Mr V Prasad , CSE Dept .

You are on page 1of 8

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-3: Read p,q,f[c][d].

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:

START

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

READ m,n,p,q

FALSE

(m==p&

&n==q)

TRUE

CAN ADD MATRIX

FALSE

for c in steps of 1 do where c<m

TRUE

STOP

FALSE

TRUE

READ f[c][d]

FALSE

TRUE

FALSE

READ s[c][d]

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

FALSE

TRUE

SUM OF MATRICES IS:

STOP

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)

{

printf(can add matrices);

}

else

{

printf(cannot add matrices);

}

printf(enter elements into first matrix);

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

{

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

{

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

}

}

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

cc wk6b.c -curses o matrixadd

Output (1)

enter rows and columns for both the matrices

2222

can add matrices

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

cannot add matrices

Original Output :

Output (1)

enter rows and columns for both the matrices

2222

can add matrices

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

can add matrices

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.

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--

- Week-15(a)Uploaded byprasad9440024661
- Week-1(a) C ProgrammingUploaded byprasad9440024661
- Week-1(c) C ProgrammingUploaded byprasad9440024661
- Week-11Uploaded byprasad9440024661
- Week-14Uploaded byprasad9440024661
- Week-16(a)Uploaded byprasad9440024661
- Week-1(b) C ProgrammingUploaded byprasad9440024661
- Week-15(b)Uploaded byprasad9440024661
- Week-3Uploaded byprasad9440024661
- Week-6(a)Uploaded byprasad9440024661
- Week-4Uploaded byprasad9440024661
- Week-5(a)Uploaded byprasad9440024661
- Week-16(b)Uploaded byprasad9440024661
- Week-2(c)Uploaded byprasad9440024661
- Week-2(b)Uploaded byprasad9440024661
- Week-2(a)Uploaded byprasad9440024661
- Week-16(c)Uploaded byprasad9440024661
- Week-5(b)Uploaded byprasad9440024661
- Week-5(c)Uploaded byprasad9440024661
- Week-6(c)Uploaded byprasad9440024661
- DBMS Lab ManualUploaded byprasad9440024661
- FOSS Lab --V Prasad,2013Uploaded byprasad9440024661
- lab12-19Uploaded byprasad9440024661
- RIT CSE Project/ Seminar CertificateUploaded byprasad9440024661
- D mathematics Notes Booklet.pdfUploaded byHadi Hassan
- CivilEngineering-2011-12Uploaded byAzmatullah Khan Sherani
- Properties of MatricesUploaded byHaider Shah
- S3-L4-PA1.pdfUploaded byShani Arain
- Sl Topics 4.1 & 4.2 Matrices Revision NotesUploaded byButchers_BL
- Dynamics of Offshore Structures_Chapter6_Structural ResponseUploaded bydavid gomeztagle

- lab12-19Uploaded byprasad9440024661
- FOSS Lab --V Prasad,2013Uploaded byprasad9440024661
- Seminar M.techUploaded byprasad9440024661
- RIT CSE Project/ Seminar CertificateUploaded byprasad9440024661
- DBMS Lab ManualUploaded byprasad9440024661
- Week-16(c)Uploaded byprasad9440024661
- Week-16(b)Uploaded byprasad9440024661
- Week-16(a)Uploaded byprasad9440024661
- Week-15(b)Uploaded byprasad9440024661
- Week-6(c)Uploaded byprasad9440024661
- Week-6(a)Uploaded byprasad9440024661
- Week-5(c)Uploaded byprasad9440024661
- Week-5(b)Uploaded byprasad9440024661
- Week-5(a)Uploaded byprasad9440024661
- Week-4Uploaded byprasad9440024661
- Week-3Uploaded byprasad9440024661
- Week-2(c)Uploaded byprasad9440024661
- Week-2(b)Uploaded byprasad9440024661
- Week-2(a)Uploaded byprasad9440024661
- Week-1(b) C ProgrammingUploaded byprasad9440024661
- 0 Cover Page.pdfUploaded byprasad9440024661

- Fill aspUploaded byAndrea Ballandino
- A Design Studio Cookbook for Dashboards Users Ian Mayor SAPUploaded byjorge_r_souza
- CSS 2 TutorialUploaded byjokoarie
- Lotus Notes ManualUploaded byacuellaralfaro
- SMC Process ChartUploaded bynurture
- Service StackUploaded byPepito Wolf
- bods2Uploaded bykishore
- Visual BasicUploaded bymatilda
- Selenium Tutorial - Course DetailsUploaded byvenkatmantra
- BrushingUpPTBasicsUploaded byArnab Mallick
- Website Vulnscan Sample ReportUploaded byबी० के० शर्मा
- C# SyllabusUploaded bySatish B basapur
- Tuning Glassfih 3.1-821-2431.pdfUploaded byRobert Williams
- STSCUploaded bytiamostar
- Symbian Operating System ArchitectureUploaded bySafena Teresa
- Dynamic SQLUploaded byKorisnik1956
- Assembler DirectivesUploaded bySivaprasad Reddy
- Java 7th Sem AshokkumarUploaded byHarshith Rai
- Computer Science Sample Papers for Class 11Uploaded byAbhishek Kumar
- ERP Short Questions (Dot.net)Uploaded byhassancheema36
- Karel the Robot Learns JavaUploaded byTugce Tasci
- Difference Between BOL and GENIL Layers in SAP CRMUploaded byBhanu Chander
- c languageUploaded byRamesh Kannan
- Customer Query Track BE Btech MCA ASP Project2Uploaded byNaveen Soni
- Implement Stack Using Queues - GeeksforGeeksUploaded bybsudheertec
- Qtp FlicksUploaded byPurna Ganti
- Calling a Web Service From an ASP.net Web PageUploaded byapex_tgi
- An Agile Request For Proposal (RFP) Process. refUploaded byKrishna Sai
- r13-0mqUploaded byEder
- web technologies Lab Manual R09 BY BHAVSINGH MALOTHUploaded byBhavsingh Maloth