# 2D array with searching and sorting

Page 1 of 1

## 2 Replies - 2681 Views - Last Post: 01 January 2009 - 08:34 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=78706&amp;s=34b7d857502170129b3ffaf882626c21&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 [email protected]

Reputation: 0
• Posts: 2
• Joined: 30-December 08

# 2D array with searching and sorting

Posted 30 December 2008 - 03:57 AM

A 2D array whose dimenoin is A[3][10]. Then search and sort all the entered elements.

[# include<iostream.h>
int main()

{ const int size=2*10;
int input;
int A[3][10];
int n=0;
int m=0;
int s,z,l=0;
int x, index;
while (n<1 || m<=9)
{
cout<<"Enter A[ "<<n<<"]"<<"["<<m<<"]";
cin>>input;
if (input>=l){
l=input;

}
else ;

A[n][m]=input;
if (m>8 && n<1){
n++;
m=0;

}
else{
m++;
}

}

for(s=0; s<=n; s++)
{
for(z=0; z<m; z++)
{
cout<<A[s][z]<<" ";
}
cout<<endl;

}
cout<<endl;
cout<<"the largest value is: "<<l<<"\n";

cout << "Enter search element: ";
cin >> x;
index = -1;

for(n=0; n<2; n++)
if(A[0][m]==x)
cout<<A[0][m]==x<<endl;
for(m=0;m<8;m++)
if(A[1][m]==x)
index =n;

if(index==-1)
else
cout << "Found at: " << index << endl;

return 0;

}
/code]

Is This A Good Question/Topic? 0

## Replies To: 2D array with searching and sorting

### #2 AmitTheInfinity

• C Surfing ∞

Reputation: 119
• Posts: 1,565
• Joined: 25-January 07

## Re: 2D array with searching and sorting

Posted 30 December 2008 - 04:37 AM

Is there any problem in that code?

and always . Then check if it's proper by preview your post.

### #3 [email protected]

Reputation: 0
• Posts: 2
• Joined: 30-December 08

## Re: 2D array with searching and sorting

Posted 01 January 2009 - 08:34 PM

I don't know the process on how to add a dimension in the codes. I only created A[2][10] dimension. Can you give me a sample of array composing a dimension of A[4][10] to set as my sample. Another thing is that i don't know how to sort the entered elements.
Thank you!

[code]

# include<iostream.h>
int main()

{ const int size=3*10;
int input;
int A[3][10];
int n=0;
int m=0;
int s,z,l=0;
int x, index;
while (n<1 || m<=9)
{
cout<<"Enter A[ "<<n<<"]"<<"["<<m<<"]";
cin>>input;
if (input>=l){
l=input;

}
else ;

A[n][m]=input;
if (m>8 && n<1){
n++;
m=0;

}
else{
m++;
}

}

for(s=0; s<=n; s++)
{
for(z=0; z<m; z++)
{
cout<<A[s][z]<<" ";
}
cout<<endl;

}
cout<<endl;
cout<<"the largest value is: "<<l<<"\n";

cout << "Enter search element: ";
cin >> x;
index = -1;

for(n=0; n<2; n++)
if(A[0][m]==x)
cout<<A[0][m]==x<<endl;
for(m=0;m<8;m++)
if(A[1][m]==x)
index =n;

if(index==-1)
else
cout << "Found at: " << index << endl;

return 0;

}

This post has been edited by [email protected]: 01 January 2009 - 08:58 PM