Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Program to find sum, subtraction, multiplication & transpose of matrices.

0 votes
asked Jan 8, 2020 by MUKESH SONI
Program to find sum, subtraction, multiplication & transpose of matrices.

3 Answers

–1 vote
answered Jan 9, 2020 by Amir (120 points)
#Create a list of lists for both variables x and y
X = [[12,7,3],
    [4 ,5,6],
    [7 ,8,9]]

Y = [[5,8,1],
    [6,7,3],
    [4,5,9]]

#Defining a variable called result

result = [[0,0,0],
         [0,0,0],
         [0,0,0]]

# iterate through rows
for i in range(len(X)):
   # iterate through columns
   for j in range(len(X[0])):
       result[i][j] = X[i][j] + Y[i][j]

for r in result:
   print(r)
commented Jan 14, 2020 by [email protected]
create a one program..not a one by one programs
0 votes
answered Jan 9, 2020 by 刘子铭 (620 points)

But you need to say in which language you want to...

I am learning C++ and here is the code:

int findSum(int x, int y) {

    return x + y;

}

int findSubtraction(int x, int y) {

    return x - y;

}

int findMultiplication(int x, int y) {

    return x * y;

}

I don't know what the transpose of matrices is.

+1 vote
answered Jan 10, 2020 by anonymous
For C language:

#include <stdio.h>

#include <conio.h>

void main()

{

         int a,b;

        printf("enter the first number: ");

        scanf("%d",&a);

        printf("enter the second number: ");

        scanf("%d",&b);

        int c=a+b;

        printf("the sum of two numbers is: %d",c);

getch();

}

Similarly for the place of subtraction and multiplication, just use c=a-b and c=a*b respectively

Also in the last printf mention the difference of the two numbers is and the product of the two numbers is respectively.
commented Jan 11, 2020 by Williams Victor Benjamin (120 points)
you didnt declare c
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...