Computer Science, asked by goms20, 9 months ago

Matrix Addition
Raju has a square shaped puzzle made up of small square pieces containing numbers on them. He wants to rearrange the puzzle by changing the element of a row into a column element and column element into a row element without altering the shape of the puzzle. Help raju to solve this puzzle. FUNCTIONAL REQUIREMENTS: int** createArray(int,int); int getElement(int**,int,int); int addMatrix(int**,int**,int**,int,int);
Input Format:

Enter the row and column of a matrix Enter the matrix

Output Format:

Addition of a matrix

Sample Input:

2

2

1

2

3

4

1

2

3

4

Sample Output:

2 4

6 8

Answers

Answered by poojan
1

Matrix Addition Program in Python, using the functions given in the data provided.

Language used : Python Programming

Program : (DYNAMIC, YOU CAN PROVIDE ANY NO.OF ROWS AND COLUMNS)

def createarray(a,b):

   x=int(input()) #no.of rows

   y=int(input()) #no.of columns

   getelement(x,y,a,b)

def getelement(x,y,a,b):

   for i in range(x*y):

       a.append(int(input()))

   for i in range(x*y):

       b.append(int(input()))

   addmatrix(x,y,a,b)

def addmatrix(x,y,a,b):

   for i in range(x):

       j=i*y

       for k in range(j,y+j):

           print(a[k]+b[k], end="  ")

       print()

a=[]

b=[]

createarray(a,b)

   

Input :

2

2

1

2

3

4

1

2

3

4

Output :

2     4

6     8

Explanation :

  • Take to empty lists and pass them through createarray() function.

  • Define a createarray() function, and ask the user to input row and column sizes.

  • Then, pass sizes and lists (which acts as arrays now as we are going to take in only integer values : so they act as arrays of type int) through function call of function getelement().

  • Create a function getelement() which takes in row*column size of elements into each arrays (2x2 matrix= 4 elements, 2x3 matrix = 6 elements).

  • Once done, pass the elements filled lists, sizes through the function call addmatrix() that adds the corresponding elements of the two lists and prints them in a matrix form. That's it.

Learn more :

1) Printing all the palindromes formed by a palindrome word.

brainly.in/question/19151384

2) Indentation is must in python. Know more about it at :

brainly.in/question/17731168

3) Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l.

brainly.in/question/15473120

4) Python program to find absolute difference between the odd and even numbers in the inputted number.

brainly.in/question/11611140

Attachments:
Similar questions