35657

Untitled

Dec 23rd, 2023
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void Print(int* arr, int size) {
  5.     for (int i = 0; i < size; i++) {
  6.         cout << *(arr + i) << " ";
  7.     }
  8.     cout << endl;
  9. }
  10.  
  11. int main() {
  12.     srand(time(NULL));
  13.  
  14.     const int size = 10;
  15.  
  16.     int arr[size];
  17.  
  18.     for (int i = 0; i < size; i++) {
  19.         *(arr + i) = rand() % 100;
  20.     }
  21.     Print(arr, size);
  22.  
  23.     for (int i = 0; i < size - 1; i += 2) {
  24.         int temp = *(arr + i);
  25.         *(arr + i) = *(arr + i + 1);
  26.         *(arr + i + 1) = temp;
  27.     }
  28.  
  29.     Print(arr, size);
  30. }
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment