#include <iostream> #include <cstdlib> #include <ctime> int main() { using namespace std; cout << "Enter size of array: "; int N; cin >> N; int * ARR = new int[N]; srand(time(0)); int i; for (i = 0; i < N; ++i) ARR[i] = rand() % 100 + 1;
cout << "Here is an original array:\n"; for (i = 0; i < N; ++i) cout << ARR[i] << " "; cout << endl;
int temp = ARR[N - 1]; for (i = N - 1; i > 0; --i) ARR[i] = ARR[i - 1]; ARR[0] = temp;
cout << "\nHere is a new array:\n"; for (i = 0; i < N; ++i) cout << ARR[i] << " "; cout << endl;
1
lst = [int(input()) for _ in range(int(input()))]
print(*[i for i in lst if i % 2 == 1])
print(len([i for i in lst if i % 2 == 1]))
2
lst = [int(input()) for _ in range(int(input()))]
print(*[i for i in lst[::-1] if i % 2 == 0])
print(len([i for i in lst if i % 2 == 0]))
3
lst = [int(input()) for _ in range(int(input()))]
print(*[i for i in lst if i % 2 == 0])
print(*[j for j in lst[::-1] if j % 2 == 1])
4(вообще индексация начинается с 0, но написано 'порядковыми')
a = [int(input()) for _ in range(int(input()))]
k = int(input('Введите k: '))
print(*[a[i] for i in range(k - 1, len(a), k)])
5(тоже самое, вторым я считаю элемент, который ввели вторым по счету, а не второй элемент по индексу)
a = [int(input()) for _ in range(int(input()))]
print(*[i for i in a[1::2]])
Пиши, если нужно исправить 4 или 5
#include <cstdlib>
#include <ctime>
int main()
{
using namespace std;
cout << "Enter size of array: ";
int N;
cin >> N;
int * ARR = new int[N];
srand(time(0));
int i;
for (i = 0; i < N; ++i)
ARR[i] = rand() % 100 + 1;
cout << "Here is an original array:\n";
for (i = 0; i < N; ++i)
cout << ARR[i] << " ";
cout << endl;
int temp = ARR[N - 1];
for (i = N - 1; i > 0; --i)
ARR[i] = ARR[i - 1];
ARR[0] = temp;
cout << "\nHere is a new array:\n";
for (i = 0; i < N; ++i)
cout << ARR[i] << " ";
cout << endl;
return 0;
}