Вопрос C++ напишите код к задаче пожалуйста

Регистрация
25 Авг 2013
Сообщения
89
Репутация
0
Спасибо
0
Монет
0
Дан двухмерный массив, состоящий из NxM (10<= N и M <=1000) целочисленных

элементов. Размерность массива вводить с клавиатуры. Написать функцию нахождения суммы элементов массива кратных 5 и не

кратных 2. Функция должна возвращать значение булевской переменной в зависимости

есть или нет элементы массива кратные 5 и не кратные 2. Сумму элементов массива

вернуть с помощью формального параметра (ссылочной переменной).
 
#include

const int MAX_SIZE = 1000;

bool findNumbers(int arr[MAX_SIZE][MAX_SIZE], int N, int M, int& sum)
{
bool hasNumbers = false;
sum = 0;

for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
if (arr[j] % 5 == 0 && arr[j] % 2 != 0)
{
hasNumbers = true;
sum += arr[j];
}
}
}

return hasNumbers;
}

int main()
{
int N, M;
int arr[MAX_SIZE][MAX_SIZE];

std::cout > N >> M;

std::cout > arr[j];
}
}

int sum;
bool hasNumbers = findNumbers(arr, N, M, sum);

if (hasNumbers)
{
std::cout
 
#include
using namespace std;

bool sum_of_elements(int arr[][1000], int n, int m, int& sum) {
bool has_element = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (arr[j] % 5 == 0 && arr[j] % 2 != 0) {
sum += arr[j];
has_element = true;
}
}
}
return has_element;
}

int main() {
int n, m;
cout > n >> m;
int arr[1000][1000];
cout arr[j];
}
}
int sum = 0;
bool has_element = sum_of_elements(arr, n, m, sum);
cout
 
Пожалуйста имейте ввиду, что этот пользователь забанен
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;ctime&gt;
#include &lt;cstdlib&gt;
#include &lt;vector&gt;
using namespace std;
bool f(vector&lt;vector&lt;int&gt;&gt; &amp;a,int &amp;s){
s=0; bool b=false;
for(auto &amp;i:a)for(auto &amp;j:i)if(j%5==0&amp;&amp;j%2)s+=j,b=true;
return b;}
int main(){
size_t n,m; int s; cout&lt;&lt;&#34;N M: &#34;; cin&gt;&gt;n&gt;&gt;m; srand(time(NULL));
vector&lt;vector&lt;int&gt;&gt; a(n, vector&lt;int&gt;(m));
for(auto &amp;i:a){for(auto &amp;j:i)
cout&lt;&lt;setw(4)&lt;&lt;(j=rand()%100); cout&lt;&lt;endl;}
if(f(a,s))cout&lt;&lt;s; else cout&lt;&lt;&#34;none&#34;; cout&lt;&lt;endl;}
 
#include
#include
#include
#include
#include

using namespace std;
using T = int;
using sum_t = long long;

size_t count(const char* prompt, size_t mn, size_t mx) {
size_t value = -1;
while (value < mn || value > mx) {
cout > value;
cin.ignore(0x1000, '\n');
}
return value;
}

void fill_random(vector& mx, T a, T b) {
if (a > b) swap(a, b);
uniform_int_distribution uid(a, b);
mt19937 gen{ random_device()() };
for (auto& row : mx) {
for (auto& x : row) {
x = uid(gen);
}
}
}

void show(const vector& mx, const streamsize w) {
for (const auto& row : mx) {
for (auto x : row) {
cout
 
Назад
Сверху