Created
April 14, 2018 16:21
-
-
Save Reflej0/765330a49c6372c7899dfb1eab552ad8 to your computer and use it in GitHub Desktop.
Intercambio de Variables en C (métodos no tradicionales)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///Intercambio utilizando algebra de bool. | |
void intercambio_algebra_bool(int* a, int* b) | |
{ | |
*a ^= *b; | |
*b ^= *a; | |
*a ^= *b; | |
} | |
///Intercambio utilizando operadores += -= | |
void intercambio_aritmetica_mejorada(int* a, int* b) | |
{ | |
*a += (*b); | |
*b = (*a)-(*b); | |
*a -= (*b); | |
} | |
///Intercambio utilizando aritmetica. | |
void intercambio_arimetica(int* a, int* b) | |
{ | |
*a = (*a)+(*b); | |
*b = (*a)-(*b); | |
*a = (*a)-(*b); | |
} | |
///Intercambio tradicional con una variable auxiliar. | |
void intercambio_tradicional(int* a, int* b) | |
{ | |
int aux = *a; | |
*a = *b; | |
*b = aux; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment