2D array with searching and sorting

A 2D array whose dimenoin is A[3][10]. then search and sort all the en

Page 1 of 1

2 Replies - 2681 Views - Last Post: 01 January 2009 - 08:34 PM Rate Topic: -----

#1 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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)
cout << "Not found!!" << endl;
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   User is offline

  • C Surfing ∞
  • member icon

Reputation: 119
  • View blog
  • 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 :code: . Then check if it's proper by preview your post.
Was This Post Helpful? 0
  • +
  • -

#3 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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)
cout << "Not found!!" << endl;
else
cout << "Found at: " << index << endl;




return 0;


}

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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1