Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. struct student { char nume[21];
  3. int nr_matricol;
  4. int cod_materie[3];
  5. float medie_materie[3];
  6. struct student *urm;};
  7. typedef struct student elem;
  8.  
  9.  
  10. int main()
  11. {
  12. int i,n;
  13. scanf("%d",&n);
  14. elem *cap_lista, *p,*q;
  15. p=(elem*)malloc(sizeof(elem));
  16. if(p==NULL) exit(1);
  17. scanf("%s",&p->nume);
  18. scanf("%d",&p->nr_matricol);
  19. scanf("%d",&p->cod_materie);
  20. scanf("%f",&p->medie_materie);
  21. p->urm=NULL;
  22. cap_lista=p;
  23. for(i=2;i<=n;i++)
  24. { q=(elem*)malloc(sizeof(elem));
  25. if(q==NULL) exit(1);
  26. scanf("%s",&q->nume);
  27. /*scanf("%d",&q->nr_matricol);
  28. scanf("%d",&q->cod_materie);*/
  29. scanf("%f",&q->medie_materie);
  30. q->urm=NULL;
  31. p->urm=q;
  32. p=q;
  33. }
  34. float sum=0;
  35. for(p=cap_lista,i+1;p!=NULL;p=p->urm,i++)
  36. sum=sum+p->medie_materie;
  37. printf("%f",sum);
  38.  
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement