Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void swap(float* a, float* b)
- {
- float temp = *a;
- *a = *b;
- *b = temp;
- }
- void ordenar(float* arreglo, int tamano)
- {
- int intercambio = 1;
- do
- {
- intercambio = 0;
- for(int i = 0; i < tamano -1; ++i)
- {
- if( arreglo[i] > arreglo[i + 1])
- {
- swap(&arreglo[i], &arreglo[i + 1]);
- intercambio = 1;
- }
- }
- } while(intercambio == 1);
- }
- void imprime(float*a, int tamano)
- {
- for(int i = 0; i < 5; ++i)
- {
- printf("a[%i] = %f\n", i, a[i]);
- }
- }
- int main()
- {
- float d = 5.0f;
- float e = 10.0f;
- swap(&d, &e);
- float a[5];
- printf("indique que numeros se deben imprimir:\n");
- for(int i = 0; i < 5; ++i )
- {
- if(i < 5)
- {
- scanf("%f", &a[i]);
- }
- }
- printf("d: %f, e: %f\n", d, e);
- imprime(a, 5);
- ordenar(a, 5);
- imprime(a, 5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement