Jump to content

Array 2d


rocking_san13

Recommended Posts

Hi I am newbie here !

I just made a program in CPP about 2D arrays.

Inputting rows and columns by user then subtracting the minimum element from row and then subtracting minimum element from the second matrix (row subtracted matrix).

Now the resulted matrix will be having zeros obviously..

Now the problem is that if a zero is selected then other zeros from that particular row and column must not be selected.... :unsure:

What condition I have to edit..

Any help would be greatly appreciated....

This I have done so far.

 

#include<iostream.h>
#include<conio.h>
void main()
{
int matrix[10][10],matrixb[10][10],matrixc[10][10];
int i,j,n,m,min[20],min2[20],max,k,l,cost=0;
char a;
clrscr();
cout<<"enter no. of r=";
cin>>n;
cout<<"enter no. of c=";
cin>>m;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
	{

	cout<<"enter r"<<i+1<<"c"<<j+1<<" :";
	cin>>matrix[i][j];
	}
}

for(j=0;j<m;j++)
{
cout<<"\tc"<<j+1;
}
for(i=0;i<n;i++)
{
cout<<"\nr"<<i+1;
for(j=0;j<m;j++)
	{
	cout<<"\t"<<matrix[i][j];
	}
}

for(i=0;i<n;i++)
{
min[i]=matrix[i][0];
for(j=0;j<m;j++)
	{
	if(min[i]>matrix[i][j])
		{
		min[i]=matrix[i][j];
		}
	 }
	}
cout<<"\nROW REDUCTION";
for(i=0;i<n;i++)
{
//min[i];
cout<<"\n";
cout<<"min="<<min[i];
	for(j=0;j<m;j++)
		{
		matrixb[i][j]=matrix[i][j]-min[i];
		cout<<"\t"<<matrixb[i][j];
		}
 }
for(j=0;j<m;j++)
{
min2[j]=matrixb[0][j];
for(i=0;i<n;i++)
	{
	if(min2[j]>matrixb[i][j])
		{
		min2[j]=matrixb[i][j];
		}
	 }
	}

cout<<"\nCOLUMN REDUCTION";
for(j=0;j<m;j++)
{
  //	min2[j];
for(i=0;i<n;i++)
	{
	matrixc[i][j]=matrixb[i][j]-min2[j];
	}
 }

for(i=0;i<n;i++)
{
cout<<"\n";
//cout<<"min="<<min2[j];

	for(j=0;j<m;j++)
		{
		cout<<"\t"<<matrixc[i][j];
		}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
	{
	 if(matrixc[i][j]==0)
		 {
		 cout<<"\n"<<"i"<<i<<"j"<<j<<"=";
		 cout<<matrix[i][j];

		 cost=cost+matrix[i][j];
		 }



	}
}
cout<<"\ncost="<<cost;
getch();
}

 

Thanx in advance :rolleyes:

Share this post


Link to post
Share on other sites

Cleaned this up. Please don't post in all caps. And also, multi-posts happen and it's no big deal. Please don't make yet another post to tell us about it. We'll gladly take care of them for you when we spot them. :thumbs-up:

Share this post


Link to post
Share on other sites

Some suggestions:

 

1. TYPING WITH CAPSLOCK ON IS ANNOYING AS HELL

2. Use the

if (cow)
return moo;
else
return shouldBeACow;

tags to keep your code easy to read.

3. When you do accidently make 3 copys of a post, making a 4th to say sorry wont help, however deleting the text in 2 of them and linking to the other one with an appoligy might be a good idea...(You can jsut report your own other posts if you want for deleting with an explination.

 

and the post I picked to reply to was deleted already :lol: See how much of a PITA that was.

Share this post


Link to post
Share on other sites

Inputting rows and columns by user then subtracting the minimum element from row and then subtracting minimum element from the second matrix (row subtracted matrix).

Now the resulted matrix will be having zeros obviously..

Now the problem is that if a zero is selected then other zeros from that particular row and column must not be selected.... :unsure:

Did you write this question or was it given to you?

 

I have an incredibly hard time understanding what you are saying.

 

Are there two matrices? Is the second matrix generated by subtracting the lowest value element from all the values of a single row of the original matrix? And then a third matrix is generated by subtracting the same lowest value from ALL matrix elements in the 2nd matrix?

 

Try and be more verbose if you worded the question/problem yourself and understand the behaviour the program is supposed to implement. Then, maybe more people will come forward to help you :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...