Está en la página 1de 2

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input
loop */
using namespace std;
int main(int argc, char** argv) {

float temporal,x[50];
int n,i,j;
cout<<"cantida numeros a leer:"; cin>>n;
//ingreso de array
for(i=0;i<n;i++)
{cout<<"elemento"<<i<<";";cin>>x[i];
}
//ordena por burbuja
//for(i=0;i<n;i++)
//for(j=n-1;j>=1;j--)
//if(x[j-1]>x[j])
//{temporal=x[j-1];
// x[j-1]=x[j];
// x[j]=temporal;
//}

for (i=1; i<n; i++)


for (j=0 ; j<n-1; j++)// ascendente
if (x[j]>x[j+1])
{temporal=x[j];
x[j]=x[j+1];
x[j+1]=temporal;
}
//muestra ordenado
cout<<"elementos ascendentes"<<endl;
for(i=0;i<n;i++)
cout<<"elemento"<<i<<"="<<x[i]<<endl;

for (i=1; i<n; i++)


for (j=0 ; j<n-1; j++)
if (x[j]<x[j+1])// descendete
{temporal=x[j];
x[j]=x[j+1];
x[j+1]=temporal;
}
//muestra ordenado
cout<<"elementos descendentes"<<endl;
for(i=0;i<n;i++)
cout<<"elemento"<<i<<"="<<x[i]<<endl;
system("pause");
return 0;
}

clude <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input
loop */
using namespace std;
int main(int argc, char** argv) {

float temporal,x[50];
int n,i,j;
cout<<"cantida numeros a leer:"; cin>>n;
//ingreso de array
for(i=0;i<n;i++)
{cout<<"elemento"<<i<<";";cin>>x[i];
}
//ordena por burbuja
for(i=0;i<n;i++)
for(j=n-1;j>=1;j--)
if(x[j-1]>x[j])//ascendente
{temporal=x[j-1];
x[j-1]=x[j];
x[j]=temporal;
}

//muestra ordenado
cout<<"elementos ascendentes"<<endl;
for(i=0;i<n;i++)
cout<<"elemento"<<i<<"="<<x[i]<<endl;

for(i=0;i<n;i++)
for(j=n-1;j>=1;j--)
if(x[j-1]<x[j])//descendente
{temporal=x[j-1];
x[j-1]=x[j];
x[j]=temporal;
}

//muestra ordenado
cout<<"elementos descendentes"<<endl;
for(i=0;i<n;i++)
cout<<"elemento"<<i<<"="<<x[i]<<endl;

system("pause");
return 0;
}

También podría gustarte