Предмет: Информатика, автор: Persik0

СИ++ 

Осуществите циклический сдвиг компонент заданного вектора A(N) влево на одну позицию, то есть получите вектор А = (a2 , a3 , ..., aN , a1 ).

#include <stdio.h>

#include <stdlib.h>

 

#include <conio.h>

 

 

 

 

Ответы

Автор ответа: AndreyGrynyuk
0

#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <cstdlib>
using namespace std;
const int SIZE = 20;
int arr[SIZE] = { -1, 1, 5, 2, -4, 0, 7, -2, 5, -9, 3,6,-9,0,-4,4,6,2,13,5 };
int main()
{
cout << "new Array:" << std::endl;
copy(arr, arr + SIZE, std::ostream_iterator<int>(std::cout, " "));
cout << std::endl;

int first= arr[0];

for (int k=0;k<SIZE-2;k++)
arr [k]=arr[k+1];
arr[SIZE-1]=first;

cout << "new Array:" << std::endl;
copy(arr, arr + SIZE, std::ostream_iterator<int>(std::cout, " "));
cout << std::endl;


system("pause");

return 0;}

Похожие вопросы