Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct{
- int cod;
- char nume[255];
- int suprafata;
- int loc;
- int venit;
- }Tara;
- Tara t[100];
- void afisare1(Tara t[], int n)
- {
- Tara aux;
- printf("\nTarile in ordine alfabetica:");
- for(int i=0;i<n-1;i++)
- {
- for(int j=i+1;j<n;j++)
- if(strcmp(t[i].nume, t[j].nume)>0)
- {
- aux=t[i];
- t[i]=t[j];
- t[j]=aux;
- }
- }
- for(int i=0;i<n;i++)
- {
- printf("\n%s, %g loc/kmp, %g venit/loc",t[i].nume,(float)t[i].loc/t[i].suprafata,(float)t[i].venit/t[i].loc);
- }
- printf("\n");
- }
- void afisare2(Tara t[],int n)
- {
- Tara aux;
- float v1,v2;
- printf("\nTarile in ordinea crescatoare a nr de loc/kmp:");
- for(int i=0;i<n-1;i++)
- {
- for(int j=i+1;j<n;j++)
- {
- v1=(float)t[i].loc/t[i].suprafata;
- v2=(float)t[j].loc/t[j].suprafata;
- if(v1>v2)
- {
- aux=t[i];
- t[i]=t[j];
- t[j]=aux;
- }
- }
- }
- for(int i=0;i<n;i++)
- {
- printf("\n%s, %g loc/kmp, %g venit/loc",t[i].nume,(float)t[i].loc/t[i].suprafata,(float)t[i].venit/t[i].loc);
- }
- printf("\n");
- }
- void afisare3(Tara t[],int n)
- {
- Tara aux;
- float v1,v2;
- printf("\nTarile in ordinea descrescatoare a venit/loc:");
- for(int i=0;i<n-1;i++)
- {
- for(int j=i+1;j<n;j++)
- {
- v1=(float)t[i].venit/t[i].loc;
- v2=(float)t[j].venit/t[j].loc;
- if(v1<v2)
- {
- aux=t[i];
- t[i]=t[j];
- t[j]=aux;
- }
- }
- }
- for(int i=0;i<n;i++)
- {
- printf("\n%s, %g loc/kmp, %g venit/loc",t[i].nume,(float)t[i].loc/t[i].suprafata,(float)t[i].venit/t[i].loc);
- }
- printf("\n");
- }
- int main()
- {
- int n;
- char s[255];
- char *p=NULL;
- printf("\nCate tari? "); scanf("%d",&n); fflush(stdin);
- for(int i=0;i<n;i++)
- {
- gets(s);
- p=strtok(s,", ");
- t[i].cod=atoi(p);
- p=strtok(NULL,", ");
- strcpy(t[i].nume,p);
- p=strtok(NULL,", ");
- t[i].suprafata=atoi(p);
- p=strtok(NULL,", ");
- t[i].loc=atoi(p);
- p=strtok(NULL,", ");
- t[i].venit=atoi(p);
- }
- afisare1(t,n);
- afisare2(t,n);
- afisare3(t,n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement