Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- using namespace std;
- struct najdaljsereke
- {
- char ime[31];
- char celina[31];
- int dolzina;
- };
- void vnos (struct najdaljsereke x[],int n);
- void izpis (struct najdaljsereke x[],int n);
- void sortiranje (struct najdaljsereke x[],int n);
- void izpis2 (struct najdaljsereke x[],int n);
- int main()
- {
- struct najdaljsereke x[3];
- vnos (x,3);
- sortiranje (x,3);
- izpis (x,3);
- //izpis2 (x,3);
- return 0;
- }
- void vnos (struct najdaljsereke x[],int n)
- {
- for (int i=0;i<n;i++)
- {
- fflush (stdin);
- cout <<"Vnesi ime reke :";
- gets (x[i].ime);
- cout <<"Vnesi celino reke :";
- gets (x[i].celina);
- cout <<"Vnesi dolzino reke :";
- cin>>x[i].dolzina;
- if(x[i].dolzina<1000)
- {
- cout<<"Saj to je potocek";
- i--;
- }
- }
- }
- void sortiranje (struct najdaljsereke x[],int n)
- {
- char pom[31];
- int poms;
- for(int i=0;i<n;i++)
- for (int j=n-1;j>i;j--)
- if(strcmp(x[j].ime,x[j-1].ime)>0)
- {
- strcpy (pom,x[j-1].ime);
- strcpy (x[j-1].ime,x[j].ime);
- strcpy (x[j].ime,pom);
- strcpy (pom,x[j-1].celina);
- strcpy (x[j-1].celina,x[j].celina);
- strcpy (x[j].celina,pom);
- poms=x[j-1].dolzina;
- x[j-1].dolzina=x[j].dolzina;
- x[j].dolzina=poms;
- }
- }
- void izpis (struct najdaljsereke x[],int n)
- {
- for(int i=0;i<n;i++)
- {
- puts (x[i].ime);
- puts (x[i].celina);
- cout <<x[i].dolzina;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement