46 lines
820 B
C
46 lines
820 B
C
#include<stdio.h>
|
|
|
|
#define TAM 5
|
|
|
|
int main(){
|
|
|
|
|
|
int vector[TAM];
|
|
int i;
|
|
int j;
|
|
int temp;
|
|
|
|
|
|
for (i=0; i<TAM; i++){
|
|
printf("\nIntroduce los valores del array: ");
|
|
scanf("%d", &vector[i]);
|
|
}
|
|
|
|
for(i=0; i<TAM; i++){
|
|
printf("\nLos valores del array son %d", vector[i]);
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
for (i=1;i<TAM;i++)
|
|
{
|
|
for (j=0; j < TAM-i ;j++) // for(j=0; j < Nelementos-i; j++) es menor y no menor igual
|
|
{
|
|
if (vector[j] > vector[j+1])//Condicion mayor-menor
|
|
{
|
|
temp=vector[j];
|
|
vector[j]=vector[j+1];
|
|
vector[j+1]=temp;
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("\nY el vector ordenado sería: ");
|
|
for(i=0; i<TAM; i++){
|
|
printf("\nLos valores del array son %d", vector[i]);
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
|
} |