Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <stdlib.h>
  2. # include <iostream>
  3. # include <windows.h>
  4. # include <time.h>
  5. # include <conio.h>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. setlocale(LC_ALL, "Russian");
  13.  
  14. int m, n, i, j, k, f;
  15. printf_s("\nВведите кол-во элементов массива1: ");
  16. scanf_s("%d", &m);
  17. printf_s("\nВведите кол-во элементов массива2: ");
  18. scanf_s("%d", &n);
  19. int* mas1 = new int [m];
  20. int* mas2 = new int [n];
  21. int* masf = new int [m + n];
  22.  
  23.  
  24. printf_s("\nВведите данные первого массива: ");
  25. for (i = 0; i < m; i++)
  26. {
  27. scanf_s("%d", &mas1[i]);
  28. }
  29. if (m+1>m)
  30. printf_s("\nВведите данные второго массива: ");
  31. for (j = 0; j < n; j++)
  32. {
  33. scanf_s("%d", &mas2[j]);
  34. }
  35. i = 0, j = 0;
  36.  
  37. for (f = 0; f < (m + n); f++)
  38. {
  39.  
  40. if (mas1[i] >= mas2[j])
  41. {
  42. masf[f] = mas2[j];
  43. j += 1;
  44. }
  45. else
  46. {
  47. masf[f] = mas1[i];
  48. i += 1;
  49. }
  50. }
  51. if (mas1[m-1] >= mas2[n-1])
  52. {
  53. masf[m+n-1] = mas1[m];
  54. }
  55. //else masf[m + n - 1] = mas2[n];
  56. for (f = 0; f < (m + n); f++)
  57. printf_s("%d ", masf[f]);
  58. system("pause");
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement