473,236 Members | 1,497 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,236 software developers and data experts.

matrix multiplication code

Hi everyone
I am new to this site and also new to programming world
can anybody help me writing C code for matrix multiplication (without using pointers)

Amit
Oct 2 '06 #1
6 61928
r035198x
13,262 8TB
Hi everyone
I am new to this site and also new to programming world
can anybody help me writing C code for matrix multiplication (without using pointers)

Amit
You'd have to try writting something first. It is eaier to help when you've shown some of your ideas first.
Oct 2 '06 #2
Hi everyone
I am new to this site and also new to programming world
can anybody help me writing C code for matrix multiplication (without using pointers)

Amit
Hi amrit...Iam writing the simple matrix multiplication code for you without using pointers...
Expand|Select|Wrap|Line Numbers
  1. /* Description:To multiply given to matrix using arrays*/
  2. #include<stdio.h>
  3. #include<math.h>
  4. main()
  5. {
  6.   int i,j,k;
  7.  int a,b,c;/*three variables to get the row and colum of the two matrix*/
  8.  int sum;
  9.  int m[10][10],n[10][10],l[10][10];
  10.  printf("The first matrix:\n");
  11.  printf("Enter the number of rows and columns for the first matrix:\t")  ;
  12.  scanf("%d%d",&a,&b);
  13.  printf("The Second matrix:\n");
  14.  printf(Enter the rows and columns of the second matrix:\t:);
  15.  scanf("%d%d",&b,&c);
  16.  
  17.  /* Note: For matrix multiplication the number of columns in the first matrix should be equal to the number of rows in the second message*/
  18.  
  19.  printf(":Enter the values of the first matrix:\n");
  20.  for(i=0;i<a;i++)
  21.    {
  22.      for(j=0;j<b;j++)
  23.        {
  24.          scanf("%d",&m[i][j]);
  25.        }
  26.    }
  27.   printf("Enter the values of the second matrix:\n");
  28.   for(i=0;i<b;i++)
  29.    {
  30.      for(j=0;j<c;j++)
  31.       {
  32.         scanf("%d",&n[i][j]);
  33.       }
  34.    }
  35.    for(i=0;i<a;i++)
  36.      {
  37.     for(j=0;j<c;j++)
  38.      {
  39.        sum=0;
  40.        for(k=0;k<b;k++)
  41.         {
  42.           sum=sum+(m[i][k]*n[k][j]);
  43.           l[i][j]=sum;
  44.         }
  45.      }
  46.   }
  47.   printf("The multiplied matrix is:\n);
  48.   for(i=0;i<a;i++)
  49.    {
  50.      for(j=0;j<c;j++)
  51.       {
  52.          printf ("%d",l[i][j]);
  53.          printf("\t");
  54.       }
  55.        printf("\n");
  56.    }
  57.  
/*This the simple way to do matrix multiplication....You can also modify the program to your own choice...*/
Mar 19 '07 #3
Hi everyone
I am new to this site and also new to programming world
can anybody help me writing C code for matrix multiplication (without using pointers)

Amit
Amit I have told you the program.just work on th logic Behind it and try to modify the program...
Mar 19 '07 #4
king99
1
Hey! Can you post the code in C++ also, I really needs this code for my homework, but you have it in C.
Dec 6 '07 #5
here is the code for c++=====>

# include <iostream.h>
# include <conio.h>
void main ()
{
clrscr();
int i,j,k,sum,a,b,c;
int m[10][10];
int n[10][10];
int l[10][10];
cout<<"ENTER THE NO. OF ROWS AND COLUMN OF FIRST MATRIX";
cin>>a>>b;
cout<<"ENTER THE VALUES OF FIRST MATRIX-";
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
{
cin>>m[i][j];
}
}
cout<<"ENTER THE NO. OF ROWS AND COLUMN OF SECOND MATRIX";
cin>>b>>c;
cout<<"ENTER THE VALUES OF SECOND MATRIX-";
for(i=0;i<b;i++)
{
for(j=0;j<c;j++)
{
cin>>n[i][j];
}
}

for(i=0;i<a;i++)
{
for(j=0;j<c;j++)
{
sum=0;
for(k=0;k<b;k++)
{
sum=sum+m[i][k]*n[k][j];
l[i][j]=sum;
}
}
}
cout<<"THE RESULTANT MATRIX IS-"<<endl;
for(i=0;i<a;i++)
{
for(j=0;j<c;j++)
{
cout<<l[i][j]<<" ";
}
cout<<endl;
}
getch();
}
May 1 '10 #6
serhun
1
======> HERE IS FOR JAVA MATRIX MULTIPLICATION
int A[][]=new int[3][3];
int B[][]=new int[3][3];
int C[][]=new int[3][3];
Scanner srh=new Scanner(System.in);
Random rnd=new Random();
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.println("Enter A: ");
A[i][j]=srh.nextInt();
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.println("Enter B: ");
B[i][j]=srh.nextInt();
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
C[i][j]=0;
for(int k=0;k<3;k++){
C[i][j]+=A[i][k]*B[k][j];
}
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.println("Value of C: "+C[i][j]);
}
}
Nov 19 '11 #7

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

Similar topics

11
by: Michael Bader | last post by:
Hi, I'm currently working on a matrix multiplication code (matrix times matrix), and have come along some interesting/confusing results concerning the running time of the (apparently) same...
15
by: christopher diggins | last post by:
Here is some code I wrote for Matrix multiplication for arbitrary dimensionality known at compile-time. I am curious how practical it is. For instance, is it common to know the dimensionality of...
0
by: lituncse | last post by:
dear friends, i have come across a problem which is difficult to solve for me.it's about starssen's matrix multiplication.in general matrix multiplication we need 8 multiplications and 4 additions...
7
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...
6
by: amitsoni.1984 | last post by:
Hi, Is there any direct function for matrix multiplication in Python or any of its packages? or do we have to multiply element by element? Thank you, Amit
1
by: Sozos | last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help. #define index(i,j,power) (((i)<<(power))+(j)) void...
8
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.