Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. ...
  2.  
  3. /*
  4.  * Exemplo de código para C
  5.  */
  6.  
  7. #define MAX 50
  8.  
  9. typedef struct aluno Aluno;
  10.  
  11. struct aluno {
  12.     float notas[3]; /* supondo que o aluno terá 3 notas. este valor pode ser alterado */
  13.     float media; /* a média será calculada à partir das notas de cada aluno */
  14.     char nome[MAX];
  15. };
  16.  
  17. int main (int argc, char **argv) {
  18.     /* cada posição do vetor corresponde a um aluno diferente */
  19.     Aluno alunos[50]; /* supondo que sao 50 alunos */
  20.    
  21.    
  22.     /* um exemplo grotesco de como acessar os campos das estruturas */
  23.     alunos[0].notas[0] = 9.3;
  24.     alunos[0].notas[1] = 9.3;
  25.     alunos[0].notas[2] = 9.3;
  26.     alunos[0].media = (alunos[0].notas[0] + alunos[0].notas[1] + alunos[0].notas[2])/3;
  27.     strcpy(nome, "João Pedro");
  28.    
  29. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement