#include "stdafx.h" #include <iostream> #include <ctime> using namespace std;
int main(void) { setlocale(LC_ALL, "Russian"); srand(time(0)); const int SIZE = 300; int arr[SIZE]; int SUM = 0; cout << "Случайные числа: \n"; for (int i = 0; i < SIZE; i++) { arr[i] = rand() % 40 - 20; cout << arr[i] << endl; } for (int i = 0; i < SIZE; i++) SUM += arr[i]; cout << "Сумма равна :" << SUM << endl;
//1 Var a,b,z:integer; function max(a,b:integer):integer; begin if a>b then max:=a else max:=b; end;
begin read(a,b); z:=max(a,2*b)*max(2*a-b,b); writeln(z); end.
//2(если имеются в виду чётные по индексу) Const n=5;
Var ar:array[1..n] of integer; i,r:integer; begin writeln('Array:'); for i:=1 to n do begin readln(ar[i]); if not(odd(i)) then r:=r+ar[i]; end; writeln(r); end.
//2(если имеются в виду чётные по значению) Const n=5; Var ar:array[1..n] of integer; i,r:integer; begin writeln('Array:'); for i:=1 to n do begin readln(ar[i]); if not(odd(ar[i])) then r:=r+ar[i]; end; writeln(r); end.
//3 Const n=2; m=3;
Var ar:array[1..n,1..m] of integer; i,j:integer; begin writeln('Matrix:'); for i:=1 to n do for j:=1 to m do begin readln(ar[i,j]); if ar[i,j]<0 then ar[i,j]:=0; end; writeln('Final matrix:'); for i:=1 to n do begin for j:=1 to m do write(ar[i,j]:4); writeln; end; end.
//4(не знаю на сколько это похоже на паркет) uses GraphABC; Const r=30; Var i,x,y:integer; begin x:=300; y:=300; maximizewindow; circle(x,y+r,r); floodfill(x,y+r,clPurple); circle(x,y-r,r); floodfill(x,y-r,clPurple); circle(x+r,y+r,r); floodfill(x+r,y+r,clPurple); circle(x-r,y-r,r); floodfill(x-r,y-r,clPurple); circle(x-r,y+r,r); floodfill(x-r,y+r,clPurple); circle(x+r,y-r,r); floodfill(x+r,y-r,clPurple); end.
//5 uses GraphABC;
Var i,x,y:integer; begin maximizewindow; Setbrushstyle(bsClear); setpencolor(clBlue); circle(300,300,15); setpencolor(clyellow); circle(315,315,15); setpencolor(clBlack); circle(330,300,15); setpencolor(clGreen); circle(345,315,15); setpencolor(clRed); circle(360,300,15); end.
//6 uses GraphABC;
Var x,y,i:integer; begin x:=0; y:=windowheight; window.Width:=windowheight; while x+10<windowwidth do begin line(x,y,x+5,y-5); line(x+5,y-5,x+10,y); line(x+10,y,x,y); sleep(10); clearwindow; inc(x); dec(y); end; line(x,y,x+5,y-5); line(x+5,y-5,x+10,y); line(x+10,y,x,y); end.
1) хотя не понятно зачем изобретать велосипед function max(a, b: integer): integer; begin max := a; if b > a then max := b; end;
begin var a:=ReadInteger('a ='); var b:=ReadInteger('b ='); writeln(max(a, 2 * b) * max(2 * a - b, b)); end. 2) const handfree = false;
begin var a:= new integer[ReadInteger('n =')]; if handfree then a := ArrRandomInteger(a.Length, -50, 50) else a := ReadArrInteger(a.Length);
writeln('Array:'); a.Println; writeln('Sum of odds by value = ', a.Where(x -> x mod 2 = 0).Sum); writeln('Sum of odds by position = ', a.Slice(0, 2).Sum); end. 3) const n = 5; m = 6; handsfree = false;
begin var a := new integer[n, m]; writeln('Данные матрицы:'); for var i := a.GetLowerBound(0) to a.GetUpperBound(0) do begin for var j := a.GetLowerBound(1) to a.GetUpperBound(1) do if handsfree then begin a[i, j] := random(-50, 50); write(a[i, j]:4, ' ') end else read(a[i, j]); writeln; end;
writeln('Вывод:'); for var i := a.GetLowerBound(0) to a.GetUpperBound(0) do begin for var j := a.GetLowerBound(1) to a.GetUpperBound(1) do begin if a[i, j] < 0 then a[i, j] := 0; write(a[i, j]:4, ' '); end; writeln; end; end.
4) не ясно что они конкретно под паркетом подразумевали uses GraphABC; const r = 30;
begin var x := r; var y := 7 * r; Brush.Color := clPurple;
for var i := 1 to 6 do Circle(x + r * i, y - r * i, r); end.
5) uses graphabc; const radius = 50;
begin var step := radius div 5; // var step := 0; var x := 2 * radius; var y := 2 * radius; SetPenWidth(radius div 10);
SetPenColor(clBlue); Drawcircle(x, y, radius); x += 2 * radius + step;
SetPenColor(clBlack); Drawcircle(x, y, radius); x += 2 * radius + step;
SetPenColor(clRed); Drawcircle(x, y, radius); y += radius + step; x := 3 * radius + step div 2;
SetPenColor(clYellow); Drawcircle(x, y, radius); x += 2 * radius + step;
SetPenColor(clLimeGreen); Drawcircle(x, y, radius); x += 2 * radius + step; end.
6) uses GraphABC; const w = 500; d = 10;
begin Window.Init(0, 0, w, w, clGreen); Window.CenterOnScreen; Brush.Color := clBlack;
for var x := 0 to Window.Width do begin var y := Window.Height - x; Sleep(10); Window.Clear(clGreen); FillPolygon((x, y), (x + d, y - d), (x + 2 * d, y)); end; end.
#include <iostream>
#include <ctime>
using namespace std;
int main(void)
{
setlocale(LC_ALL, "Russian");
srand(time(0));
const int SIZE = 300;
int arr[SIZE];
int SUM = 0;
cout << "Случайные числа: \n";
for (int i = 0; i < SIZE; i++)
{
arr[i] = rand() % 40 - 20;
cout << arr[i] << endl;
}
for (int i = 0; i < SIZE; i++)
SUM += arr[i];
cout << "Сумма равна :" << SUM << endl;
system("pause");
return 0;
}