fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int a [] = {10,11,20} ;
  8. int b [] = {12,15,27,30} ;
  9. int sz1 = sizeof(a)/ sizeof(a[0]);
  10. int sz2 = sizeof(b)/ sizeof(b[0]);
  11. int c [sz1+sz2] ;
  12. int i = 0, j = 0, x = 0 ;
  13. for ( ; i < sz1 && j < sz2 ; ){
  14. if ( a[i] <= b[j]) c[x++] = a[i++];
  15. else c[x++] = b[j++];
  16. }
  17. if (i < sz1){
  18. for ( int j = i ; j < sz1 ; j++ ) c[x++] = a[j];
  19. }
  20. if (j < sz2){
  21. for ( int i = j ; i < sz2 ; i++ ) c[x++] = b[i];
  22. }
  23. for (int i = 0 ; i < sz1+sz2 ; i++) cout << c[i] << " " ;
  24. return 0;
  25. }
  26.  
  27.  
  28.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
10 11 12 15 20 27 30