leutira notas/CPF estruturas
Página 1 de 1
leutira notas/CPF estruturas
# 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);
}
}
# 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- Esperto
- Mensagens : 74
Data de inscrição : 30/11/2010
Tópicos semelhantes
» CADASTRO USANDO ESTRUTURAS
» media notas/ alocacao dinamica
» CADASTRO USANDO ESTRUTURAS E IMPRIMIR
» EQUAÇÃO SEGUNDO GRAU (ESTRUTURAS)
» vetores e ponteiros para estrutura. LEITURAS DE NOTAS /CPF
» media notas/ alocacao dinamica
» CADASTRO USANDO ESTRUTURAS E IMPRIMIR
» EQUAÇÃO SEGUNDO GRAU (ESTRUTURAS)
» vetores e ponteiros para estrutura. LEITURAS DE NOTAS /CPF
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos
|
|