#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;
procedure PrintArray(var a: array100); var i: integer; begin for i := 1 to n do write(a[i]:3, ' '); writeln; end;
begin randomize; for i := 1 to n do a[i] := random(99) - 50;
PrintArray(a);
repeat f := true; for i := 1 to n - 1 do if (a[i] < 0) and (a[i + 1] >= 0) then begin f := false; t := a[i]; a[i] := a[i + 1]; a[i + 1] := t; end; until f; PrintArray(a);
readln; end.
0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota
Оформи подписку