Advertisement
codeido

מבוא למדעי המחשב תרגול 12 תרגיל 6

Jan 21st, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void print_alternatively(int array[], int size)
  6. {
  7.     // גודל המערך שלם, חיובי ואי-זוגי
  8.     if (size == 1)
  9.     {
  10.         cout << array[0];
  11.     }
  12.     else
  13.     {
  14.         cout << array[0] << " " << array[size - 1] << " ";
  15.         print_alternatively(array + 1, size - 2);
  16.     }
  17. }
  18.  
  19. int main()
  20. {
  21.     int array[] = {12, 3, 4, 9, 15};
  22.     int size = 5;
  23.  
  24.     print_alternatively(array, size);
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement