473,508 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with a Matrix Multiplication program

1 New Member
Ok, I have an assignment to write a program that multiplies two matrices. The matrices dimensions will be user defined as well as the numbers (floating point values) inside of them. The program must check to see if the two matrices are able to be multiplied.


This is the code that I have so far:

#include "stdafx.h"
#include <iostream>

using namespace std;

void main()
{
int row1, row2, col1, col2 = 0;

cout << "This program will multiply two matrices that you create. Enter in the number of rows in the first matrix: ";
cin >> row1;
cout <<"Now please enter in the number of columns: ";
cin >> col1;
cout << "Please enter the number of rows in the second matrix: ";
cin >> row2;
cout << "Please enter in the number of columns: ";
cin >> col2;

if(col1 != row2)
{
cout << "in order to multiply two matrices the number of columns in the first matrix must match the number of rows in the second << endl << Enter in the number of rows in the first matrix: ";
cin >> row1;
cout <<"Now please enter in the number of columns: ";
cin >> col1;
cout << "Please enter the number of rows in the second matrix: ";
cin >> row2;
cout << "Please enter in the number of columns: ";
cin >> col2;
}


}

Now where I get confused is creating the arrays for the two matrices. The professor says that they must be dynamically allocated and they must be 1-dimensional arrays. This is his advice on how to do that:
[row][col] -> [row*rowSize + col]
I don't quite understand what exactly that statement means, any explanation on that would be appreciated.
Dec 10 '07 #1
1 1945
mschenkelberg
44 New Member
It means make a one-D array row*col in size and when you want to access an item in 2-D format, instead of having a 2D array and using arr[row][col] you would use your 1d array and access it by doing arr[ NUMROWS*ROWyouWANTtoACCESS + COLyouWANTtoACCESS].

Max
Dec 10 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1950
by: Silver | last post by:
Hi everyone, my program compiles and executes, but I get an error during run-time. I guess it has something to do with memory allocation (which I don't seem to fully control yet).. Here's the...
7
1472
by: Silver | last post by:
First of all...merry christmas everyone! Now, I have to write a program. Among other things, I need to overload the '*' operator, so that it returns a pointer-to-ponter of type int, which is...
7
1727
by: Jim | last post by:
Hi people. I was hoping someone could help me as this is driving me up the wall. I'm trying to write a program that deals with matrix multiplication. The Program uses a couple of typedefined...
20
5184
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've...
2
2107
by: wuzertheloser | last post by:
Develop a program which computes the current value of the vector {x} based on the following forward iteration: {x}(n+1) = {x}(n), n = 0,1,2, ... ,8,9. In other words, the next vector {x} is...
1
1787
by: raylegendkiller | last post by:
NEED TO MAKE A PROGRAM which computes the current value of the vectors {x} based on the following forward iterations: this >>> {x}(n+1) = {x}(n), n = 0,1,2, ... ,8,9. In other...
7
7560
by: VijaKhara | last post by:
Hi all, Is there any method which can implememt the matrix multiplication faster than using the formula as we often do by hand? I am writing the following code and my matrice: one is 3x40000 and...
0
2794
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free...
8
7862
by: joegao1 | last post by:
can some one give me a hint? I want to program the code for matrix multiplication with as less arithmetical / multiplication operations as possible. my task is to calculate the matrix...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.