I have a problem on programming, its not really my assignment,
but my friends...

i just thought i can resolve this at C, because i got some backgrounds on it..
but i can't do it

my compiler is dev c++
the code must be on C++ not C

can i know the simplest code that can add, subtract and multiply matrices
in one single program only?

maybe something like

1.asking me the dimensions of the 1st matrix and the 2nd matrix
2.input the values for the 1st matrix then second matrix
3.then ask what operation

then the answer...

i will very much appreciate it,if you add some comments on lines that are significant...

thanks

You don't even want to try so you want us to program it for you? That's what you're saying, right?

i've tried it, but i cant work on putting them together...

check this out, i wasnt able to run this, i got some errors...

what do you think about this

void product(int x[10][10],int y[10][10],int r1,int c1,int c2)
{
int i,j,c[10][10],k;
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
{
c[i][j]+=x[i][k]*y[k][i];
}
}
}
}

I also found this in the net and i can't keep up with the codes...
and i am thinking if there is some errors on it or its just the difference of the compiler...

I use devc++ and here is the code that i cant troubleshoot...

can you help me...please

#include<iostream.h>
#include<conio.h>
#include<process.h>
int a[10][10],b[10][10],x[10][10];
void add()
	{
	int r,c,i,j,n;
	cout<<"ENTER THE ORDER OF MATRIX : ";
	cin>>n;
	r=n;
	c=n;
	cout<<"ENTER THE ELEMENTS FOR MATRIX 'A' :"<<endl;
	for(i=0;i<r;i++)
		{
		for(j=0;j<c;j++)
			{
			cin>>a[i][j];
			}
		}
	cout<<"ENTER THE ELEMENTS FOR MATRIX 'B' : "<<endl;
	for(i=0;i<r;i++)
		{
		for(j=0;j<c;j++)
			{
			cin>>b[i][j];
			}
		}
	clrscr();

	cout<<"MATRIX 'A' IS "<<endl;
	for(i=0;i<r;i++)
		{
		for(j=0;j<c;j++)
			{
			cout<<a[i][j]<<" ";
			}
		cout<<endl;
		}

	cout<<"MATRIX 'B' IS "<<endl;
	for(i=0;i<r;i++)
		{
		for(j=0;j<c;j++)
			{
			cout<<b[i][j]<<" ";
			}
		cout<<endl;
		}
//.....................ADDITION OF MATRIX........................

	for(i=0;i<r;i++)
		{
		for(j=0;j<c;j++)
			{
			x[i][j]=a[i][j]+b[i][j];
			}
		}

	cout<<"THE SUM OF TWO ENTERED MATRIX IS "<<endl;
	for(i=0;i<r;i++)
		{
		for(j=0;j<c;j++)
			{
			cout<<x[i][j]<<"  ";
			}
		cout<<endl;
		}
	}

void multiply()
	{
	int r1,c1,r2,c2,i,j,k;
	clrscr();
	cout<<"ENTER THE NO.OF ROWS OF MATRIX (A) : ";
	cin>>r1;
	cout<<"ENTER THE NO.OF COLOUMS OF MATRIX (A) :";
	cin>>c1;
	cout<<"ENTER THE ELEMENTS FOR MATRIX (A) :"<<endl;
	for(i=0;i<r1;i++)
		{
		for(j=0;j<c1;j++)
			{
			cin>>a[i][j];
			}
		}

	cout<<"ENTER THE NO.OF ROWS OF MATRIX (B) : ";
	cin>>r2;
	cout<<"ENTER THE NO.OF COLOUMS OF MATRIX (B) : ";
	cin>>c2;
	cout<<"ENTER THE ELEMENTS FOR MATRIX (B) :"<<endl;
	for(i=0;i<r2;i++)
		{
		for(j=0;j<c2;j++)
			{
			cin>>b[i][j];
			}
		}

	clrscr();
	cout<<"MATRIX 'A' IS "<<endl;
	for(i=0;i<r1;i++)
		{
		for(j=0;j<c1;j++)
			{
			cout<<a[i][j]<<" ";
			}
		cout<<endl;
		}

	cout<<"MATRIX 'B' IS "<<endl;
	for(i=0;i<r2;i++)
		{
		for(j=0;j<c2;j++)
			{
			cout<<b[i][j]<<" ";
			}
		cout<<endl;
		}

	if(c1!=r2)
		{
		cout<<"MULTIPLICATION IS NOT POSSIBLE ";
		}
	else
		{
		for(i=0;i<r1;i++)
			{
			for(j=0;j<c2;j++)
				{
				x[i][j]=0;
				for(k=0;k<c1;k++)
					{
					x[i][j]=x[i][j]+(a[i][k]*b[k][j]);
					}
				}
			}
		}

	cout<<"MULTIPLICATION OF TWO MATRIX IS "<<endl;
	for(i=0;i<r1;i++)
		{
		for(j=0;j<c2;j++)
			{
			cout<<x[i][j]<<"  ";
			}
		cout<<endl;
		}
	}

void main()
{
clrscr();
while(1)
{
int ch;
cout<<"

";
cout<<"...ENTER YOUR CHOICE........"<<endl;
cout<<"1. ADDITION OF TWO MATRIX "<<endl;
cout<<"2. MULTIPLICATION OF TWO MATRIX "<<endl;
cout<<"3. EXIT "<<endl;
cin>>ch;
switch(ch)
	{
	case 1:
		add();
		break;
	case 2:
		multiply();
		break;
	case 3:
		exit(0);
	default :
		cout<<"INVALID CHOICE !! ENTER CORRECT CHOICE";
	}
getch();
}
}

i've tried it, but i cant work on putting them together...

Hello spixy,
You have combined matrix addition and multiplication. Do them separately and there is no need of loop k.

c[i][j]+=x[i][k]*y[k][i];

Edited 5 Years Ago by Arbus: n/a

@arbos and pdot

i really appreciate your help guys...
problem is, i need it on one program,
and i need it in C++ language

i haven't started vb, i don't even finished c, or c++
and i guess im still to far...

please help me, i badly need this now, friday...
awwww

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