Program Task; Const N = 499; M = 1; Var A: Array [1..N, 1..N] of Boolean; i, j, x, y, t: Integer; b: Boolean; Begin Randomize; While i < M Do Begin x := Random(N) + 1; y := Random(N) + 1; If A[x, y] = False Then Begin A[x, y] := True; i := i + 1; End; End; While b = False Do Begin b := True; For i := 1 To N Do For j := 1 To N Do Begin If A[i, j] = True Then Begin If (i + 1) <= N Then A[i + 1, j] := True; If (i - 1) > 0 Then A[i - 1, j] := True; If(j + 1) <= N Then A[i, j + 1] := True; If (j -1) > 0 Then A[i, j - 1] := True; End; End; For i := 1 To N Do For j := 1 To N Do If A[i, j] = False Then b := False; t := t + 1; End; WriteLn(t); ReadLn; End.
Задача 1:
#include <iostream>
using namespace std;
int main()
{
int a{}, b{};
cout << "a = ";
cin >> a;
cout << endl << "b = ";
cin >> b;
if (a < b) a *= 2, b *= 3;
else b *= 2, a *= 3;
cout << endl << endl << "a = " << a << endl << "b = " << b;
return 0;
}
Задача 2:
#include <iostream>
using namespace std;
int main()
{
int a{};
cout << "a = ";
cin >> a;
if (!(a % 2)) cout << endl << a * a; //if (!(a % 2)) = теж саме, що й if (a % 2 == 0)
else cout << endl << a * a * a;
return 0;
}
Задача 3:
#include <iostream>
using namespace std;
int main()
{
int sum{};
for (int i = 11; i < 100; i += 2) sum += i;
cout << sum;
return 0;
}
Задача 4:
#include <iostream>
using namespace std;
int main()
{
for (int i = 144; i < 1000; i += 48) cout << i << " ";
return 0;
}