Advertisement
KvArt

Fuzija dva uredjenja niza

Aug 16th, 2022
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 100
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6. void main()
  7. {
  8.     while(1)
  9.         {
  10.             int na,nb,i;
  11.             printf("Unesite duzinu niza na: "); scanf("%d",&na);
  12.             if (na<0 || na>N) break;
  13.             printf("Unesite elemente niza: "); int a[N];
  14.             for(i=0;i<na; scanf("%d",&a[i++]));
  15.             if (na==0) printf("\n");
  16.            
  17.             printf("Unesite duzinu niza nb: "); scanf("%d",&nb);
  18.             if (nb<0 || nb>N) break;
  19.             printf("Unesite elemente niza: "); int b[N];
  20.             for(i=0;i<nb; scanf("%d",&b[i++]));
  21.             if (nb==0) printf("\n");
  22.            
  23.             int ia=0, ib=0, ic=0, c[2*N];
  24.             while (ia<na && ib<nb) c[ic++]= (a[ia]<b[ib]) ? a[ia++] : b[ib++];
  25.             while (ia<na) c[ic++] = a[ia++];
  26.             while (ib<nb) c[ic++] = b[ib++];
  27.             int nc=ic;
  28.             printf("Rezultujuci niz C izgleda ovako: "); for(ic=0; ic<nc; printf("%d ",c[ic++]));      
  29.                        
  30.             //printf("Niz nakon obrade izgleda ovako: "); for(i=0; i<n; printf("%d ",a[i++]));
  31.             printf("\n\n");
  32.         }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement