Skip to content

Instantly share code, notes, and snippets.

@joaoBeno
Created October 29, 2019 23:57
Show Gist options
  • Save joaoBeno/5d0a7bdc43cf6ac29aee92de40495037 to your computer and use it in GitHub Desktop.
Save joaoBeno/5d0a7bdc43cf6ac29aee92de40495037 to your computer and use it in GitHub Desktop.
Exercicio ponteiros
#include <stdio.h>
void troca(float *a, float *c, float *b);
int main() {
float x, y, z;
printf("Digite os numeros:\n");
scanf("%f,%f,%f", &x, &y, &z);
troca(&x,&y,&z);
printf("numeros: %.0f, %.0f, %.0f", x, y, z);
return 0;
}
void troca(float *a, float *b, float *c) {
float max, min;
max = (*a > *b) ? *a : *b;
max = (max > *c) ? max : *c;
min = (*a < *b) ? *a : *b;
min = (min < *c) ? min : *c;
*b = (*b != min && *b != max) ? *b : ((*a != min && *a != max) ? *a : *c);
*a = max;
*c = min;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment