Thread: bubble sort array in acending and descending order

1. bubble sort array in acending and descending order

Code:
```#include<iostream>
using namespace std;
int main(void)
{//declaration of variables
int i;
int num[10];
int temp;

for (i=0; i<=9; i++)
{
cin>>num[i];
}

cout<<"you entered \t";
for (i=0; i<=9; i++)
{
cout<<num[i]<<"\t";
}
cout<<endl;
/*
if (i<=-100 || i<=100)
{
cin>>i;
}*/

for(int i=0; i<10; i++) //sort numbers in ascending order
{
for(int y=0; y<9; y++)
{
if (num[y]<num[y+1])
{
temp=num[y+1];  //swapping
num[y+1]=num[y];
num[y]=temp;
}
}
}

cout<<"sorted number in ascending order are\t";
for (int i=0; i<10; i++)
{
cout<<num[i]<<"\t";
}
cout<<endl;

// sort numbers in
for(int i=0; i<10; i++)
{
for(int y=0; y>i; y++)
{
if (num[y]>num[y+1])
{
temp=num[y+1];  //swapping
num[y+1]=num[y];
num[y]=temp;
}
}
}

cout<<"sorted number in descending order are\t";
for (int i=0; i<10; i++)
{
cout<<num[i]<<"\t";
}
cout<<endl;
system("PAUSE");
return 0;
}

above is my half working program, i just couldn't figure out a way to get a ascending sort to work. Can someone give me a hand? thanks```