# Sorting Arrays

Page 1 of 1

## 1 Replies - 340 Views - Last Post: 12 March 2009 - 04:02 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=92290&amp;s=410256507a741323278b2078b82fbaa2&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 lynn16

• New D.I.C Head

Reputation: 0
• Posts: 12
• Joined: 11-December 08

# Sorting Arrays

Posted 12 March 2009 - 03:42 AM

```{ int elements[N] = {3,-4,12,9,-1}, x[N] = {3,-4,12,9,-1}, i, j, temp;
for (i=0;i<=N;i++)
{ for (j=i+1;j<N;j++)
{ if (elements[i]<elements[j])
{ temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
```

the values of elements [N] will still be the same after the program runs right?

This post has been edited by lynn16: 12 March 2009 - 03:43 AM

Is This A Good Question/Topic? 0

## Replies To: Sorting Arrays

### #2 tjust80

Reputation: 11
• Posts: 73
• Joined: 01-December 08

## Re: Sorting Arrays

Posted 12 March 2009 - 04:02 AM

try this

```#define N 10
main()
{
int elements[N] = {3,-4,12,100,89,2,14,-150,9,-1}, i, j, temp;

for (i=0;i<N;i++)
{
for (j=i+1;j<N;j++)
{
if (elements[i]<elements[j])
{
temp = elements[i];
elements[i] = elements[j];
elements[j] = temp;
}
}
}
for (i=0;i<N;i++)
{
cout << elements[i] << endl;
}
}

```

This post has been edited by tjust80: 12 March 2009 - 04:03 AM