// PascalABC.NET 3.0, сборка 1128 procedure Convert(V:array of integer); begin for var i:=0 to V.Length-1 do if V[i]>9 then V[i]:=9 else if V[i]<5 then V[i]:=5 end;
procedure Develop(c:char; k:integer); begin WritelnFormat('*** Массив {0} ***',c); var a:=ArrRandom(k,-5,15); Write('исходный : '); a.PrintLn(','); Convert(a); Write('результат: '); a.PrintLn(','); end;
begin var m:=ReadInteger('Количество элементов в массиве A:'); var n:=ReadInteger('Количество элементов в массиве B:'); Develop('A',m); Develop('B',n) end.
Тестовое решение: Количество элементов в массиве A: 15 Количество элементов в массиве B: 10 *** Массив A *** исходный : 6,5,-5,9,1,0,-3,9,13,12,-4,8,11,14,-5 результат: 6,5,5,9,5,5,5,9,9,9,5,8,9,9,5 *** Массив B *** исходный : 5,12,12,4,7,9,7,-3,-1,-2 результат: 5,9,9,5,7,9,7,5,5,5
#include <iostream>
#include <ctime>
int main()
{
srand(time(NULL));
const int arraySize = 10;
int mainArray[arraySize];
for (int i = 0; i < arraySize; i++)
mainArray[i] = rand() % 1000;
int maxNum = mainArray[0];
for (int i = 0; i < arraySize; i++)
if (mainArray[i] > maxNum)
maxNum = array[i];
std::cout << maxNum << std::endl;
system("pause");
return 0;
}
#2:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float
a_coef,
b_coef,
c_coef;
cout << "Input the coefficients (a * x^2 + b * x + c): ";
cin >> a_coef >> b_coef >> c_coef;
float res1, res2;
res1 = (-b_coef + sqrt(b_coef * b_coef - 4 * a_coef * c_coef)) / (2 * a_coef);
res2 = (-b_coef - sqrt(b_coef * b_coef - 4 * a_coef * c_coef)) / (2 * a_coef);
cout << res1 << "; " << res2 << endl;
system("pause");
return 0;
}
#3:
#include <iostream>
#include <ctime>
int main()
{
srand(time(NULL));
int
unknownNumber = rand() % 100 - 50,
attempts = 0,
inputtedNumber;
while (true)
{
attempts++;
cout << "Input the number: ";
cin >> inputtedNumber;
if (inputtedNumber != unknownNumber)
cout << "Incorrect answer! Try again!" << endl;
else
break;
}
cout << "Attempts: " << attempts;
system("pause");
return 0;
}