Not Yet Answered # product of two matrices with undefined number of rows and columns

Calipe -1 Ancient Dragon 5,243 Aia 1,977 Calipe -1 Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...

-5

I know you need your implementation in C but I hope this program in Python that I created is somewhat helpful.

```
# -------------------------------------------------------------------
# Function: init
# Purpose: Program's initialization function (i.e. Point of entry)
# ------------------------------------------------------------------
def init():
print("")
print("|-----| Matrix Multiplier |-----|")
print("")
print("Programmed by: Carlos Felipe Perea")
print("This program is distributed in accordance to the GNU GPL License version 3")
print("")
print("Purpose: Multiplies two matrices and prints the result on screen")
print("To call this program again, use the 'init' function")
print("")
print("IMPORTANT: The number of columns in the first matrix must eqaul")
print("the number of rows in the second matrix")
print("")
matrix_A = []
matrix_B = []
result_matrix = []
# Ask the user for the dimensions of matrix A and matrix B
try:
matrix_A_row = int(input("Insert the number of rows for matrix A: "))
matrix_A_col = int(input("Insert the number of columns for matrix A: "))
matrix_B_row = int(input("Insert the number of rows for matrix B: "))
matrix_B_col = int(input("Insert the number of columns for matrix B: "))
print("")
except:
print("Error: The value must be a positive integer")
return []
# If the number of columns in matrix A is not equal to the number of rows in column B
# then print an error message on screen and escape
if matrix_A_col != matrix_B_row:
print("Error: The number of columns in matrix A must be equal to the number of rows in matrix B")
return []
# Ask for the elements of each matrix
i = 0
while i < matrix_A_row:
row = []
ii = 0
while ii < matrix_A_col:
row.append(int(input("Matrix A - Row " + str(i + 1) + ", Column " + str(ii + 1) + ": ")))
ii = ii + 1
matrix_A.append(row)
i = i + 1
displayMatrix(matrix_A, "----- Matrix A -----")
i = 0
while i < matrix_B_row:
row = []
ii = 0
while ii < matrix_B_col:
row.append(int(input("Matrix B - Row " + str(i + 1) + ", Column " + str(ii + 1) + ": ")))
ii = ii + 1
matrix_B.append(row)
i = i + 1
displayMatrix(matrix_B, "----- Matrix B -----")
# Create an empty matrix with the correct dimensions for the product matrix
i = 0
while i < matrix_A_row:
row = []
ii = 0
while ii < matrix_B_col:
row.append(0)
ii = ii + 1
result_matrix.append(row)
#print(result_matrix[i])
i = i + 1
i = 0
# Multiply each row of matrix A times each column of matrix B
while i < len(result_matrix):
ii = 0
while ii < len(result_matrix[0]):
result_matrix[i][ii] = multiplyRowCol(i, ii, matrix_A, matrix_B)
ii = ii + 1
i = i + 1
print("")
displayMatrix(result_matrix, "***** Result *****")
return result_matrix
# -------------------------------------------------------------------------------------
# Function: multiplyRowCol
# Purpose: Multiplies matrix A's element at position 'i' times matrix B's elements at
# position 'i' and adds all of this products and returns the result
# -------------------------------------------------------------------------------------
def multiplyRowCol(rowA, colB, matrixA, matrixB):
length = len(matrixA[rowA])
result = 0
i = 0
while i < length:
result = result + matrixA[rowA][i] * matrixB[i][colB]
i = i + 1
return result
# -------------------------------------------------
# Function: displayMatrix
# Purpose: Displays each row of the matrix on a
# separate line of the shell
# -------------------------------------------------
def displayMatrix(matrix, title = ""):
print("")
if title != "":
print(title)
i = 0
while i < len(matrix):
print(matrix[i])
i = i + 1
print("")
# INITIALIZATION ------------------------------------------------
init()
```

*Edited 7 Years Ago by Calipe*: n/a

0

Please i need d code for C.

Stop whining and begging. The code he provided is practically C.

0

Please i need d code for C.

The rules of this forum clearly explain that we do not give away code to posters that do not show proof of effort. Where's the code? Where is your effort in the matter?

-1

Please i need d code for C.

If you were to just make an effort to translate the code that I gave to you C you would have what you need. Algorithms are practical and applicable to all programming languages given you know the language...which I'm guessing you don't.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hello All ...

Iam Getting An Error With try to excecute the stored procedure .

I have Have Sql database , the stored procedure like so :

```
USE [MPRS]
GO
/****** Object: StoredProcedure [dbo].[Search_Licenses_By_Number] Script Date: 26-Nov-16 8:06:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE ...
```

Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"

Here is the sample output that I ...