Advertisement
heian

Untitled

May 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct Carte
  5. {
  6. char ISBN[18];
  7. double pret;
  8. short nr_exemplare;
  9.  
  10. }Carte;
  11.  
  12.  
  13. double pretMediu(Carte v[],int n)
  14. {
  15. int i;
  16. /**
  17. v: (isbn1, 100, 5) (isbn2, 200, 10) (isbn3, 50, 3)
  18.  
  19. */
  20.  
  21. double suma=0;
  22. int nr_total_exemplare=0;
  23. for(i=1;i<=n;i++)
  24. {
  25. suma = suma + (v[i].pret * v[i].nr_exemplare);
  26. nr_total_exemplare+=v[i].nr_exemplare;
  27. }
  28.  
  29. suma = suma/nr_total_exemplare;
  30. return suma;
  31. }
  32.  
  33. void afisareISBN(Carte v[],int n)
  34. {
  35. FILE *f;
  36. f=fopen("carti.out","w");
  37. double pret_mediu=pretMediu(v,n);
  38. for(int i=1;i<=n;i++)
  39. if(v[i].pret>pret_mediu)
  40. {
  41. fprintf(f,"%s ",v[i].ISBN);
  42. }
  43. }
  44.  
  45. int main()
  46. {
  47. Carte v[5001];
  48. int n;
  49.  
  50. FILE *f;
  51. f=fopen("carti.in","r");
  52. fscanf(f, "%d", &n);
  53. for(int i=1;i<=n;i++)
  54. {
  55. fscanf(f,"%s",v[i].ISBN);
  56. fscanf(f,"%lf",&v[i].pret);
  57. fscanf(f,"%hd",&v[i].nr_exemplare);
  58. }
  59. afisareISBN(v,n);
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement