Advertisement
Velja_Programer

Sortiranje imena

Mar 13th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 20
  4. #define D 30
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6. void uredi (char niz[][D+1],int n)
  7. {
  8.     int i,j,m;
  9.     char p[D+1];
  10.     for(i=0;i<n-1;i++){
  11.         for(m=i,j=i+1;j<n;j++)
  12.             if(strcmp (niz[j],niz[m])<0) m=j;
  13.     if( m!=i)
  14.     {
  15.         strcpy (p, niz[i]);
  16.         strcpy (niz[i],niz[m]);
  17.         strcpy (niz[m],p);
  18.       }
  19.    }
  20. }
  21. int main(int argc, char *argv[]) {
  22.     char niz[N][D+1];
  23.     int n=0,i;
  24.     printf("NIZ IMENA? \n");
  25.     do
  26.         gets(niz[n]);
  27.         while (strlen(niz[n++]) > 0);
  28.         n--;
  29.         uredi (niz,n);
  30.         printf ("\n UREDJENI NIZ IMENA: \n");
  31.         for (i=0;i<n;puts (niz[i++]));
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement