473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Program (Calculation of Matrix Product)

#include <stdio.h>
#define MAX 100

int main() {
int m, n, /* dimensoes da matriz A */
nb, p, /* dimensoes da matriz B */
i, j, k;
float A[MAX][MAX], B[MAX][MAX], C[MAX][MAX];

printf("Digite as dimensoes (mXn) da matriz A: ");
scanf("%d", &m);
scanf("%d", &n);
printf("Digite a matriz A:\n");
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
scanf("%f", &A[i][j]);

printf("Digite as dimensoes (nXp) da matriz B: ");
scanf("%d", &nb);
scanf("%d", &p);
if (nb != n)
printf("Nao existe o produto da matriz A por B!!");
else {
printf("Digite a matriz B:\n");
for (i = 0; i < n; i++)
for (j = 0; j < p; j++)
scanf("%f", &B[i][j]);

/* calculo do produto */
for (i = 0; i < m; i++)
for (j = 0; j < p; j++){
C[i][j] = 0;
for (k = 0; k < n; k++)
C[i][j] = C[i][j] + A[i][k] * B[k][j];
}

/* impressao do resultado */
printf("Matriz A X B: \n");
for (i = 0; i < m; i++) {
for (j = 0; j < p; j++)
printf("%f ", C[i][j]);
printf("\n");
}
}

return 0;
}

Jan 5 '07 #1
3 1928
This is C++ but it should be easy enough to translate it to C:
http://cap.connx.com/chess-engines/n...h/strassen.zip

Originally, I think it was C (some student project from the internet),
but I went and translated it.

Typical reasoning says that Strassen matrix multiplication only pays
off when the matrix is very large. That typical reasoning is wrong.

It was not clear to me from your post what you were wanting in reply.
Perhaps a code review? Comments for improvements? If you give some
additional feedback, I can probably say something that is actually
helpful.

Jan 5 '07 #2
look this example that uses dynamic memory llocation :
http://www.vandersongold.com.br/downloads/mul_matriz.c

On 5 jan, 17:37, "user923005" <dcor...@connx.comwrote:
This is C++ but it should be easy enough to translate it to C:http://cap.connx.com/chess-engines/n...h/strassen.zip

Originally, I think it was C (some student project from the internet),
but I went and translated it.

Typical reasoning says that Strassen matrix multiplication only pays
off when the matrix is very large. That typical reasoning is wrong.

It was not clear to me from your post what you were wanting in reply.
Perhaps a code review? Comments for improvements? If you give some
additional feedback, I can probably say something that is actually
helpful.
Jan 5 '07 #3

va************@gmail.com wrote:
look this example that uses dynamic memory llocation :
http://www.vandersongold.com.br/downloads/mul_matriz.c
/* aloca as linhas da matriz */

v = calloc (m, sizeof(float *)); /* Um vetor de m ponteiros para float
*/
if (v == NULL) {

printf ("** Erro: Memoria Insuficiente **");

return (NULL);

}

/* aloca as colunas da matriz */

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

v[i] = calloc (n, sizeof(float)); /* m vetores de n floats */

if (v[i] == NULL) {

printf ("** Erro: Memoria Insuficiente **");

/*
vector of float pointers v[] was never freed.
individual columns v[j] for j = 0 to i are not freed.
*/
return (NULL);

}

}

Jan 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
11
by: bob | last post by:
Hi, given a vector of vectors of strings thus; typedef std::vector<std::string> product; typedef std::vector<product> product_matrix; whats the fastest, most efficient means of streaming...
6
by: Chris Buckett | last post by:
Hi, I was just wondering if anyone has had any experience in developing a shipping matrix. We are based in the UK, and we need to ship both locally and internationally. Local shipping is...
5
by: wudoug119 | last post by:
1. The program should be able to solve the following problems a. decision to be made if a given number is a prime b. Fibonacci number calculation (F1=1, F2=1, Fn=Fn-2+Fn-1) c. determinant...
1
by: robert2032survey | last post by:
G'day all I am building a calculation application. The design of the application is made in matlab. I converted the script into Perl. Because of performance issues Perl was not quick enough. In...
25
by: batwings | last post by:
Hii i have an assignment to submit in my course work Advance Algorithms n it is due on april-19th. So anyone pls help me writing the code for the question given...
2
by: DarrenWeber | last post by:
Below is a module (matrix.py) with a class to implement some basic matrix operations on a 2D list. Some things puzzle me about the best way to do this (please don't refer to scipy, numpy and...
12
by: spima05 | last post by:
Hello I am developing a database to calculate commissions on a sale for each rep involved in the same and their uplines. Below is the database structure and the commissions schedule. I am...
2
by: rijaalu | last post by:
I am designing a matrix class that performs addition, multicpication, substraction and division. When ever i complie the code it shows an error. include <iostream> using namespace std; class...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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
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...

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.