Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void swap(float* a, float* b)
  4. {
  5.     float temp = *a;
  6.     *a = *b;
  7.     *b = temp;
  8. }
  9. void ordenar(float* arreglo, int tamano)
  10. {
  11.     int intercambio = 1;
  12.     do
  13.         {
  14.             intercambio = 0;
  15.             for(int i = 0; i < tamano -1; ++i)
  16.                 {
  17.                     if( arreglo[i] > arreglo[i + 1])
  18.                         {
  19.                             swap(&arreglo[i], &arreglo[i + 1]);
  20.                             intercambio = 1;
  21.                         }
  22.                 }
  23.         } while(intercambio == 1);
  24. }
  25. void imprime(float*a, int tamano)
  26. {
  27.      for(int i = 0; i < 5; ++i)
  28.     {
  29.      printf("a[%i] = %f\n", i, a[i]);
  30.     }
  31. }
  32. int main()
  33. {
  34.     float d = 5.0f;
  35.     float e = 10.0f;
  36.     swap(&d, &e);
  37.     float a[5];
  38.     printf("indique que numeros se deben imprimir:\n");
  39.     for(int i = 0; i < 5; ++i )
  40.     {
  41.         if(i < 5)
  42.         {
  43.             scanf("%f", &a[i]);
  44.         }
  45.     }
  46.     printf("d: %f, e: %f\n", d, e);
  47.     imprime(a, 5);
  48.     ordenar(a, 5);
  49.     imprime(a, 5);
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement