Advertisement
KvArt

Fuzija dva niza u prvi uneti niz

Aug 16th, 2022
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 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,ia,ib,ic;
  11.             printf("Unesite duzinu niza na: "); scanf("%d",&na);
  12.             if (na<0 || na>N) break;
  13.             printf("Unesite elemente niza a: "); int a[2*N];
  14.             for(ia=0; ia<na; scanf("%d",&a[ia++]));
  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 b: "); int b[N];
  20.             for(ib=0; ib<nb; scanf("%d",&b[ib++]));
  21.             if (na==0) printf("\n");       
  22.            
  23.             ia = na - 1, ib = nb -1, ic = (na+=nb) -1;
  24.             while (ia>=0 && ib >=0) a[ic--] = (a[ia]>b[ib]) ? a[ia--] : b[ib--];
  25.             while (ib >= 0 ) a[ic--] = b[ib--];
  26.             printf("\nNiz nakon obrade izgleda ovako: "); for(ia=0; ia<na; printf("%d ",a[ia++]));
  27.             printf("\n\n");
  28.         }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement