473,405 Members | 2,279 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,405 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 61939
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...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.