Advertisement
Combreal

shiftIntTab.cpp

Jan 19th, 2020
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void shiftTab(int tab[], int tabSize, int pos)
  5. {
  6.     int teb[5];
  7.     int counter = 0;
  8.     int counterB = 0;
  9.     for (int i = pos; i < tabSize; i++)
  10.     {
  11.         teb[counter] = tab[i];
  12.         counter++;
  13.     }
  14.     if (counter != tabSize)
  15.     {
  16.         counterB = counter;
  17.         for (int i = 0; i < tabSize - counter; i++)
  18.         {
  19.             teb[counterB] = tab[i];
  20.             counterB++;
  21.         }
  22.     }
  23.     for (int i = 0; i < 5; i++)
  24.     {
  25.         tab[i] = teb[i];
  26.     }
  27. }
  28.  
  29. int main()
  30. {
  31.     int tab[] = { 1,2,3,4,5 };
  32.     size_t theSize= sizeof(tab) / sizeof(tab[0]);
  33.     shiftTab(tab, theSize, 1);
  34.     for (size_t i = 0; i < theSize; i++)
  35.     {
  36.         cout << tab[i] << ' ';
  37.     }
  38.     cout << endl;
  39.     system("pause");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement