Возможный вариант в C++ #include <iostream> int main() { using namespace std; int N; cout << "Enter N: "; cin >> N; int num; int max = 1; int i; for (i = 0; i < N; ++i) { cout << "Enter #" << i + 1 << " number: "; cin >> num; if ((num - 9) % 10 != 0 && num % 3 == 0) { max = num; break; } } for (int j = i + 1; j < N; ++j) { cout << "Enter #" << j + 1 << " number: "; cin >> num; if ((num - 9) % 10 != 0 && num % 3 == 0) if (num > max) max = num; } if (max != 1) cout << "Max number div by 3 and don't end 9: " << max << endl; else cout << "No numbers div by 3 and don't end 9" << endl; return 0; }
PascalABC
Объяснение:
1)
begin
WriteLn('Введите размер массива N: ');
var n := ReadInteger;;
var a := ArrRandomInteger(n, -20, 20);
a.PrintLn;
WriteLn('Сумма элементов, которые оканчиваются на число 2, равна ', a.Where(x -> (x mod 10 = 2) or (x mod 10 = -2)).Sum);
end.
2)
begin
var a := ArrRandomInteger(10, -10, 10);
a.PrintLn;
WriteLn('Индексы отрицательных нечетных элементов:');
foreach var i in a.Indices do
if (a[i].IsOdd) and (a[i] < 0) then Write(i, ', ');
end.
#include <iostream>
int main()
{
using namespace std;
int N;
cout << "Enter N: ";
cin >> N;
int num;
int max = 1;
int i;
for (i = 0; i < N; ++i)
{
cout << "Enter #" << i + 1 << " number: ";
cin >> num;
if ((num - 9) % 10 != 0 && num % 3 == 0)
{
max = num;
break;
}
}
for (int j = i + 1; j < N; ++j)
{
cout << "Enter #" << j + 1 << " number: ";
cin >> num;
if ((num - 9) % 10 != 0 && num % 3 == 0)
if (num > max)
max = num;
}
if (max != 1)
cout << "Max number div by 3 and don't end 9: " << max << endl;
else
cout << "No numbers div by 3 and don't end 9" << endl;
return 0;
}