Advertisement
Guest User

Estrutura de Dados

a guest
Apr 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5. //struct em global
  6.  
  7. int i,j;
  8. int n = 2;
  9.  
  10. struct RgData{
  11.     int dia;
  12.     int mes;
  13.     int ano;   
  14. };
  15.  
  16. struct RgAluno{
  17.     char nome[35];
  18.     float nota[4];
  19.     float media;
  20.     struct RgData data;
  21. };
  22.  
  23. void lerDados(struct RgAluno* p){
  24.     float soma;
  25.     //Leitura e armazenamento dos dados
  26.     for(i=0; i<n; i++){
  27.         soma = 0;
  28.         fflush(stdin);
  29.         printf("\nDigite o nome: ");
  30.         gets(p[i].nome);
  31.         printf("Digite a data de nascimento (DD MM AAAA): ");
  32.         scanf("%d %d %d",&p[i].data.dia, &p[i].data.mes, &p[i].data.ano);
  33.         printf("Digite as quatro notas\n");
  34.         for(j=0; j<4; j++){
  35.             printf("Nota %d:",(j+1));
  36.             fflush(stdin);
  37.             scanf("%f", &p[i].nota[j]);
  38.         soma = soma + p[i].nota[j];
  39.         }
  40.         p[i].media = soma / 4;     
  41.     }
  42. }
  43.  
  44. void Imprime(struct RgAluno* p){
  45.     //Realiza a impressao
  46.     printf("\n--- Impressao de Nomes e Notas ---\n");
  47.     for(i=0; i<n; i++){
  48.         printf("\n\nNome: %s", p[i].nome);
  49.         printf("\nData de Nasc.: %d/%d/%d", p[i].data.dia, p[i].data.mes, p[i].data.ano);
  50.         for(j=0; j<4; j++){
  51.             printf("\nNota %d: %.2f", (j+1), p[i].nota[j]);
  52.         }
  53.         printf("\nMedia: %.2f", p[i].media);
  54.     }
  55. }
  56. int main(int argc, char *argv[]) {
  57.    
  58.     struct RgAluno Aluno [5];
  59.    
  60.     lerDados(Aluno);
  61.     Imprime(Aluno);
  62.    
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement