Created
February 19, 2018 15:00
-
-
Save tiagohm/848a86c10f12a6effd3459499b3ab77b to your computer and use it in GitHub Desktop.
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
//a memória para os parâmetros será alocada dessa forma: [n][p0][p1][...][pn] | |
//por isso usamos o endereço de n para obter o endereço dos outros parametros. | |
unsigned calcular_media(char n, ... ) { | |
char i; | |
unsigned res = 0; | |
for(i = 1; i <= n; i++) { | |
res += ((char*)&n)[i]; //aponta para o i-esimo parametro e recupera seu valor. | |
} | |
return (res / n); | |
} | |
void main() { | |
//calcula a media aritmetica dos 10 números. | |
unsigned media = calcular_media(10, 11, 3, 4, 5, 6, 6, 8, 7, 6, 14); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment