Skip to content

Instantly share code, notes, and snippets.

@tiagohm tiagohm/ellipsis.c
Created Feb 19, 2018

Embed
What would you like to do?
//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
You can’t perform that action at this time.