Advertisement
Guest User

Numero

a guest
Jun 25th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. void ingresar(int * array,int numelementos)
  4. {
  5. int tmp;
  6. for(int i = 0;i<numelementos;i++){
  7. printf("Ingresa Elemento del arreglo numero %d \n",i );
  8. scanf("%d",&tmp);
  9. *(array + i) = tmp;
  10. tmp = 0;
  11. }
  12.  
  13. }
  14.  
  15. void mostrar(int * array,int tam)
  16. {
  17. for(int i = 0;i<tam;i++){
  18. printf("%d \n",*(array+i));
  19. }
  20. }
  21.  
  22. void ordenar(int * array,int tam){
  23. int temporal;
  24. for(int i = 0; i<tam;i++){
  25. for(int j= 0;j<tam -1 ;j++)
  26. {
  27. if (*(array+j) > *(array+j+1)){ // Ordena el array de mayor a menor, cambiar el "<" a ">" para ordenar de menor a mayor
  28. temporal = *(array+j);
  29. *(array+j) = *(array+j+1);
  30. *(array+j+1) = temporal;
  31. }
  32. }
  33. }
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39. int tam;
  40.  
  41.  
  42. printf("Ingresa el numero de elementos \n");
  43. scanf("%d",&tam);
  44. int * arreglo=new int[tam];
  45. ingresar(arreglo,tam);
  46. printf("Los Numeros ingresados en ese orden son\n");
  47. mostrar(arreglo,tam);
  48. ordenar(arreglo,tam);
  49. printf("Los Numeros ordenados son\n");
  50. mostrar(arreglo,tam);
  51.  
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement