Last active
August 29, 2015 14:17
-
-
Save Bolinha1/e3a17b7a65d6144fbb3b to your computer and use it in GitHub Desktop.
structs in C
This file contains hidden or 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> | |
#include <stdlib.h> | |
#define m 100 | |
typedef struct aluno{ | |
int codigo; | |
float nota; | |
}*Paluno,Aluno; | |
Paluno tab[m]; | |
void lerDadosAlunos(quantidade) | |
{ | |
float nota; | |
int i; | |
for(i = 0; i < quantidade; i++) | |
{ | |
tab[i] = (Paluno)malloc(sizeof(Aluno)); | |
printf("Digite a nota.: \n"); | |
scanf("%2f", &tab[i]->nota); | |
} | |
} | |
float imprimeNotasAlunos(quantidade) | |
{ | |
int i; | |
for(i = 0; i < quantidade; i++) | |
{ | |
printf("%.2f \n", tab[i]->nota); | |
printf("%p \n", &tab[i]->nota); | |
} | |
} | |
float media(quantidade) | |
{ | |
int i; | |
float soma; | |
for(i=0 ; i < quantidade; i++) | |
{ | |
soma+= tab[i]->nota; | |
} | |
printf("%.2f \n", soma/quantidade); | |
return soma; | |
} | |
int main() | |
{ | |
int quantidade; | |
printf("Informe a quantidade de aluno "); | |
scanf("%d", &quantidade); | |
lerDadosAlunos(quantidade); | |
imprimeNotasAlunos(quantidade); | |
media(quantidade); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment