wrench786

Lab task - (Array - 1)

Oct 7th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define uom unordered_map
  6. #define pb push_back
  7. #define yes cout<<"YES\n"
  8. #define no cout<<"NO\n"
  9.  
  10. #define dot(x) fixed<<setprecision(x)
  11. #define wrench786 ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  12.  
  13. #define PI (acos(-1.0))
  14. #define eps 0.00001
  15. const int LIMIT = 10000*500;
  16. const int mod = 1000000007;
  17. using namespace std;
  18.  
  19. int main(){
  20. int n1,n2,i,j;
  21. cout<<"Size of Array – 1: N1 ="<<endl;
  22. cin>>n1;
  23. int arr1[n1];
  24. cout<<"Enter "<<n1<<" array elements"<<endl;
  25. for(i=0;i<n1;i++){
  26. cin>>arr1[i];
  27. }
  28.  
  29. cout<<"Size of Array – 2: N2 ="<<endl;
  30. cin>>n2;
  31. int arr2[n2];
  32. cout<<"Enter "<<n2<<" array elements"<<endl;
  33. for(i=0;i<n2;i++){
  34. cin>>arr2[i];
  35. }
  36.  
  37. int arr3[n1+n2];
  38. for(i=0;i<n1;i++){
  39. arr3[i]= arr1[i];
  40. }
  41.  
  42. for(j=0;j<n2;j++,i++){
  43. arr3[i]= arr2[j];
  44. }
  45.  
  46. for(i=0;i<n1+n2-1;i++){
  47. for (j = 0; j < n1+n2-i-1; j++){
  48. if (arr3[j] > arr3[j+1]) swap(arr3[j], arr3[j+1]);
  49. }
  50. }
  51. cout<<"Merged Array in Sorted order"<<endl;
  52. for(i=0;i<n1+n2;i++){
  53. cout<<arr3[i]<<" ";
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment