Created
October 29, 2019 23:57
-
-
Save joaoBeno/5d0a7bdc43cf6ac29aee92de40495037 to your computer and use it in GitHub Desktop.
Exercicio ponteiros
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
#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