SHARE
TWEET

Untitled

a guest Sep 11th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*  Formirajte strukturu:
  2.     struct Mezimac:
  3.     {
  4.     char ime[20];
  5.     char pasmina[20];
  6.     }
  7. Inicijalizirajte niz od 7 takvih struktura i ispisite
  8. imena mezimaca cija je pasmina "pas", abecednim redom! */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. struct Mezimac{
  15.     char ime[20];
  16.     char pasmina[20];
  17. };
  18.  
  19. int main(void){
  20.    
  21.     struct Mezimac M[7];
  22.     int i,j;
  23.     char pasmina[4]="pas";
  24.     char pom1[20];
  25.     char pom2[20];
  26.    
  27.    
  28.     for(i=0;i<7;i++){
  29.         printf("Unesite ime %d. mezimca: ",i+1);
  30.         gets(M[i].ime);
  31.         printf("Unesite pasminu %d. mezimca: ",i+1);
  32.         gets(M[i].pasmina);
  33.     }
  34.    
  35.     for(i=0;i<7;i++){
  36.         for(j=i+1;j<7;j++){
  37.             if(strcmp(M[i].ime,M[j].ime)>0){
  38.                 strcpy(pom1,M[i].ime);
  39.                 strcpy(M[i].ime,M[j].ime);
  40.                 strcpy(M[j].ime,pom1);
  41.                 strcpy(pom2,M[i].pasmina);
  42.                 strcpy(M[i].pasmina,M[j].pasmina);
  43.                 strcpy(M[j].pasmina,pom2);
  44.             }
  45.         }
  46.     }
  47.    
  48.     for(i=0;i<7;i++){
  49.         if(strcmp(M[i].pasmina,pasmina)==0){
  50.             puts(M[i].ime);
  51.         }
  52.     }
  53.    
  54.     return 0;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top