#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;
begin writeln('Задача 1, введите n ='); read(n); for i := 1 to n do if i mod 2 = 0 then x := x + 1 / (2 * i + 1) else x := x - 1 / (2 * i + 1); writeln('Sum = ', x);
writeln('Задача 2, введите a, b, c, d ='); read(a, b, c, d); for i := a to b do if i mod c = d then writeln(i);
writeln('Задача 3, введите n и n чисел ='); read(n); a := 0; b := 0; c := 0; for i := 1 to n do begin read(p); if p = 0 then a := a + 1 else if p < 0 then b := b + 1 else if p > 0 then c := c + 1; end; writeln(a, ' ', b, ' ', c);
writeln('Задача 5, введите x, p ,y ='); read(x, p, y); n := 0; repeat x := round(x * (100 + p)) / 100; n := n + 1; until x >= y; writeln(n, ' лет');
writeln('Задача 6, введите A, B ='); read(a, b); repeat if (a mod 2 = 0) and (a div 2 >= b) then begin writeln(a, ' : 2 = ', a div 2); a := a div 2 end else begin writeln(a, ' - 1 = ', a - 1); a := a - 1; end; until a <= b; end.
#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;
}
a, b, c, d, i, n, p: integer;
x, y: real;
begin
writeln('Задача 1, введите n =');
read(n);
for i := 1 to n do
if i mod 2 = 0 then
x := x + 1 / (2 * i + 1)
else x := x - 1 / (2 * i + 1);
writeln('Sum = ', x);
writeln('Задача 2, введите a, b, c, d =');
read(a, b, c, d);
for i := a to b do
if i mod c = d then writeln(i);
writeln('Задача 3, введите n и n чисел =');
read(n);
a := 0; b := 0; c := 0;
for i := 1 to n do
begin
read(p);
if p = 0 then a := a + 1
else if p < 0 then b := b + 1
else if p > 0 then c := c + 1;
end;
writeln(a, ' ', b, ' ', c);
writeln('Задача 5, введите x, p ,y =');
read(x, p, y);
n := 0;
repeat
x := round(x * (100 + p)) / 100;
n := n + 1;
until x >= y;
writeln(n, ' лет');
writeln('Задача 6, введите A, B =');
read(a, b);
repeat
if (a mod 2 = 0) and (a div 2 >= b) then begin
writeln(a, ' : 2 = ', a div 2);
a := a div 2
end
else begin
writeln(a, ' - 1 = ', a - 1);
a := a - 1;
end;
until a <= b;
end.