Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void ingresar(int * array,int numelementos)
- {
- int tmp;
- for(int i = 0;i<numelementos;i++){
- printf("Ingresa Elemento del arreglo numero %d \n",i );
- scanf("%d",&tmp);
- *(array + i) = tmp;
- tmp = 0;
- }
- }
- void mostrar(int * array,int tam)
- {
- for(int i = 0;i<tam;i++){
- printf("%d \n",*(array+i));
- }
- }
- void ordenar(int * array,int tam){
- int temporal;
- for(int i = 0; i<tam;i++){
- for(int j= 0;j<tam -1 ;j++)
- {
- if (*(array+j) > *(array+j+1)){ // Ordena el array de mayor a menor, cambiar el "<" a ">" para ordenar de menor a mayor
- temporal = *(array+j);
- *(array+j) = *(array+j+1);
- *(array+j+1) = temporal;
- }
- }
- }
- }
- int main()
- {
- int tam;
- printf("Ingresa el numero de elementos \n");
- scanf("%d",&tam);
- int * arreglo=new int[tam];
- ingresar(arreglo,tam);
- printf("Los Numeros ingresados en ese orden son\n");
- mostrar(arreglo,tam);
- ordenar(arreglo,tam);
- printf("Los Numeros ordenados son\n");
- mostrar(arreglo,tam);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement