Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct Carte
- {
- char ISBN[18];
- double pret;
- short nr_exemplare;
- }Carte;
- double pretMediu(Carte v[],int n)
- {
- int i;
- /**
- v: (isbn1, 100, 5) (isbn2, 200, 10) (isbn3, 50, 3)
- */
- double suma=0;
- int nr_total_exemplare=0;
- for(i=1;i<=n;i++)
- {
- suma = suma + (v[i].pret * v[i].nr_exemplare);
- nr_total_exemplare+=v[i].nr_exemplare;
- }
- suma = suma/nr_total_exemplare;
- return suma;
- }
- void afisareISBN(Carte v[],int n)
- {
- FILE *f;
- f=fopen("carti.out","w");
- double pret_mediu=pretMediu(v,n);
- for(int i=1;i<=n;i++)
- if(v[i].pret>pret_mediu)
- {
- fprintf(f,"%s ",v[i].ISBN);
- }
- }
- int main()
- {
- Carte v[5001];
- int n;
- FILE *f;
- f=fopen("carti.in","r");
- fscanf(f, "%d", &n);
- for(int i=1;i<=n;i++)
- {
- fscanf(f,"%s",v[i].ISBN);
- fscanf(f,"%lf",&v[i].pret);
- fscanf(f,"%hd",&v[i].nr_exemplare);
- }
- afisareISBN(v,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement