Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

FINAL PRACTICAL OF FOCP

NAME: SANDEEP KAUR


UID: 21BCS2458
GROUP: 208_B
SUBMITTED TO: MRS. ROBIN KHURANA

AIM OF THE EXPERIMENT: Write a program to perform matrix


operations Addition using Array.

BASIC CONCEPT USED:


In this program, the user has to enter the numbers of rows and
columns by using separate loops for them. Then the user is asked to
enter the elements of the two matrices.
We then added corresponding elements of two matrices and saved
them in another matrix. And finally, the result is printed.

ALGORITHM:
STEP 1: START
STEP 2: DECLARE MATRIX a[i][j]; and MATRIX b[i][j]; and
MATRIX c[i][j]; where i is the number of rows and j is number of
columns.
STEP 3: Read a[ ][ ] and b[ ][ ]
STEP 4: Declare variable i=0, j=0.
STEP 5: Repeat until i<3.
STEP 6: Repeat until j<3.
STEP 7: c[i][j] = a[i][j] + b[i][j].
STEP 8: j++, i++.
STEP 9: C is the required matrix after the addition of two matrixes a
and b.
STEP 10: STOP.

CODE:
CODE:
#include <stdio.h>
int main()
{
int a[3][3];
int i ,j ;

for(i=0 ; i<3 ; i++ ){


for(j =0; j<3 ; j++){
printf("enter the array elements [%d] [%d]", i , j);
scanf("%d " , &a[i][j]);

}
}
printf("2D array element a:\n" );
for(i=0 ; i<3 ; i++ ){
for(j =0; j<3 ; j++){
printf("%d " , a[i][j]);
if(j==2){
printf("\n");
}
}
}

int b[3][3];

for(i=0 ; i<3 ; i++ ){


for(j =0; j<3 ; j++){
printf("enter the array elements [%d][%d] " , i , j);
scanf("%d " , &b[i][j]);
if(j==1){
printf("\n");
}

}
}
printf("2D array element a:\n" );
for(i=0 ; i<3 ; i++ ){
for(j =0; j<3 ; j++){
printf("%d " , b[i][j]);
if(j==2){
printf("\n");
}
}
} int c[3][3] ;
for(i=0 ; i<3 ; i++ ){
for(j =0; j<3 ; j++){
c[i][j]= a[i][j] + b[i][j];
printf("%d + %d =%d" , a[i][j], b[i][j] , c[i][j]);
}
}

printf("2D array element c:\n" );


for(i=0 ; i<3 ; i++ ){
for(j =0; j<3 ; j++){
printf("%d\t" , c[i][j]);
if(j==2){
printf("\n");
}
}
}
return 0;
}

OUTPUT:
LEARNING OUTCOMES:
1. I learned about the use of arrays in addition to the matrix.
2. I learned 2D arrays and learn how to implement them.
3. I learned how to put an array of elements in its matrix form.
4. I learned how to make a program using mathematics concepts.
5. I learned complex codes of c programming.

Evaluation Grid (To be filled by Faculty):


Sr. Parameters Marks Maximum
No. Obtained Marks
1. Worksheet completion including 10
writing learning objectives/Outcomes.
(To be submitted at the end of the day)
2. Post Lab Quiz Result. 5
3. Student Engagement in 5
Simulation/Demonstration/Performanc
e and Controls/Pre-Lab Questions.
Signature of Faculty (with Date): Total Marks 20
Obtained:

You might also like