mirror of
https://gitlab.com/blau_araujo/cblc.git
synced 2025-05-10 02:26:36 -03:00
atualização da aula 6
This commit is contained in:
parent
7560d3a58c
commit
9ca337fea2
3 changed files with 40 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
|
||||||
// Função variádica (número indeterminado de argumentos)...
|
// Função variádica (número indeterminado de argumentos)...
|
||||||
float vf_avg(int count, ...);
|
float vf_avg(int count, ...);
|
||||||
|
|
||||||
|
@ -8,8 +9,6 @@ float vf_avg(int count, ...);
|
||||||
float cf_avg(float a, float b, float c, float d);
|
float cf_avg(float a, float b, float c, float d);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
float nota1 = 7.5;
|
float nota1 = 7.5;
|
||||||
|
@ -35,9 +34,10 @@ int main(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Função comum...
|
||||||
|
float cf_avg(float a, float b, float c, float d) {
|
||||||
|
return (a + b + c + d) / 4;
|
||||||
|
}
|
||||||
|
|
||||||
// Função variádica...
|
// Função variádica...
|
||||||
float vf_avg(int count, ...) {
|
float vf_avg(int count, ...) {
|
||||||
|
@ -53,7 +53,3 @@ float vf_avg(int count, ...) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Função comum...
|
|
||||||
float cf_avg(float a, float b, float c, float d) {
|
|
||||||
return (a + b + c + d) / 4;
|
|
||||||
}
|
|
||||||
|
|
34
aulas/06-vetores/testes.c
Normal file
34
aulas/06-vetores/testes.c
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define NBIM 4
|
||||||
|
|
||||||
|
float favg(float *arr, int size) {
|
||||||
|
float sum = 0;
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
sum += arr[i];
|
||||||
|
}
|
||||||
|
return sum / size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
|
||||||
|
float notas[NBIM];
|
||||||
|
|
||||||
|
notas[0] = 7.5;
|
||||||
|
notas[1] = 9.0;
|
||||||
|
notas[2] = 8.3;
|
||||||
|
notas[3] = 8.6;
|
||||||
|
|
||||||
|
float avg = favg(notas, NBIM);
|
||||||
|
|
||||||
|
puts("============");
|
||||||
|
|
||||||
|
for (int i = 0; i < NBIM; i++)
|
||||||
|
printf("Bim. %d: %.1f\n", i + 1, notas[i]);
|
||||||
|
|
||||||
|
puts("------------");
|
||||||
|
printf("Média : %.1f\n", avg);
|
||||||
|
puts("============");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -19,7 +19,7 @@
|
||||||
vetor = endereço na memória ↑ ↑ ↑ ↑ ↑
|
vetor = endereço na memória ↑ ↑ ↑ ↑ ↑
|
||||||
Total de 16 bytes +----- 4 bytes -----+----- 4 bytes -----+----- 4 bytes -----+----- 4 bytes -----+
|
Total de 16 bytes +----- 4 bytes -----+----- 4 bytes -----+----- 4 bytes -----+----- 4 bytes -----+
|
||||||
↑ ↑
|
↑ ↑
|
||||||
&vetor+0 &vetor+4 (*)
|
&vetor+0 &vetor+1 (*)
|
||||||
|
|
||||||
|
|
||||||
(*) Problema: acesso fora dos limites do vetor!
|
(*) Problema: acesso fora dos limites do vetor!
|
||||||
|
|
Loading…
Add table
Reference in a new issue