Advertisement
satriafu5710

Program Menyalin Elemen Array C++

Nov 12th, 2022
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.     int A[6] = {1, 2, 3, 4, 5, 6};
  8.     int B[3];
  9.     int C[3];
  10.  
  11.     cout << "\n\t Menyalin Setengah Elemen Array \n\n";
  12.  
  13.     cout << " Elemen A : ";
  14.     for (int i = 0; i < 6; i++)
  15.     {
  16.  
  17.         cout << " " << A[i];
  18.     }
  19.  
  20.     cout << "\n Elemen B : ";
  21.     for (int j = 0; j < 6; j++)
  22.     {
  23.  
  24.         if (j <= 2)
  25.         {
  26.  
  27.             B[j] = A[j];
  28.  
  29.             cout << " " << B[j];
  30.         }
  31.         else
  32.         {
  33.  
  34.             C[j] = A[j];
  35.         }
  36.     }
  37.  
  38.     cout << "\n Elemen C : ";
  39.     for (int k = 0; k < 6; k++)
  40.     {
  41.  
  42.         if (k <= 2)
  43.         {
  44.  
  45.             B[k] = A[k];
  46.         }
  47.  
  48.         else
  49.         {
  50.  
  51.             C[k] = A[k];
  52.  
  53.             cout << " " << C[k];
  54.         }
  55.     }
  56.  
  57.     cout << endl
  58.          << endl;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement