SANDPIPERS CLAN
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

leutira notas/CPF estruturas

Ir para baixo

leutira notas/CPF estruturas Empty leutira notas/CPF estruturas

Mensagem por VonDuke Dom Set 01, 2013 3:48 pm

# include<stdio.h>
# include<stdlib.h>
struct aluno
{
char mat[12];
char nome[121];
float nota1, nota2, media, final, mediafinal;
};
typedef struct aluno ALUNO;
void preenche(ALUNO **tab, int i);
void inicializa(int n, ALUNO **tab);
void imprime_tudo(int n, ALUNO **tab);
void imprime(int i, ALUNO **tab);
#define MAX 100
ALUNO *tab[MAX];

int main(void)
{
int n, i;
printf("leitura de n\n");
do{
printf("digite o valor de n\n");
scanf("%d", &n);
}
while ((n<1)||(n>MAX));
inicializa (n, tab);
for(i=0;i<n;i++)
{
preenche(tab,i);
imprime(i, tab);
}

system("pause");
return 0;
}

void inicializa(int n, ALUNO **tab)
{
int i;
for(i=0;i<n;i++)
{
tab[i]=NULL;
}
}


void preenche (ALUNO **tab, int i)
{
if(tab[i]==NULL)
{
tab[i]=(ALUNO *)malloc(sizeof(ALUNO));
}
printf("digite o cpf\n");
scanf(" %12[^\n]", tab[i]->mat);
printf("digite o nome\n");
scanf(" %121[^\n]", tab[i]->nome);
printf("digite nota1\n");
scanf("%f", &tab[i]->nota1);
printf("digite nota2\n");
scanf("%f", &tab[i]->nota2);
if((tab[i]->nota1 + tab[i]->nota2)/2.0<7.0)
{
printf("digite nota da final\n");
scanf("%f", &tab[i]->final);
}
printf("digite media final\n");
scanf("%f", &tab[i]->mediafinal);
}


void imprime_tudo(int n, ALUNO **tab)
{
int i;
for(i=0;i<n ; i++)
{
imprime(i, tab);
}
}

void imprime(int i, ALUNO **tab)
{
if(tab[i]!= NULL)
{
printf("nome: %s\n", tab[i]->nome);
printf("cpf: %s\n", tab[i]->mat);
printf("media final: %f\n", tab[i]->mediafinal);
}
}
VonDuke
VonDuke
Esperto
Esperto

Mensagens : 74
Data de inscrição : 30/11/2010

Ir para o topo Ir para baixo

Ir para o topo

- Tópicos semelhantes

 
Permissões neste sub-fórum
Não podes responder a tópicos