Napisanie krótkiego programu w C++

0

Witam,

Proszę o pomoc w zadaniu C++.

W funkcji main jest tablica wypelniona liczbami. Napisz funkcję o nazwie zera, która zamienia w tablicy liczby ujemne na zera i zwraca funkcji warunek wywolujący liczbę wstawionych zer. Funkcja main wyświetla tę liczbę.

1

30 zł.

2
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	auto zeros = [](auto &x){
		auto result = count_if(begin(x), end(x), [](auto e){return e<0;});
		transform(begin(x), end(x), begin(x), [](auto e){return e<0?0:e;});
		return result;
	};
	vector<int> container = {1, -2, 3, -4, 5, -6};
	auto result = zeros(container);
	cout << result << ": ";
	for(auto e : container)
		cout << e << " ";
	return 0;
}

lub

template<typename Iterator>
size_t zeros(Iterator beginIt, Iterator endIt){
    auto res = 0;
    transform(beginIt, endIt, beginIt, [&](const auto &e){return e<0?++res, 0:e;});
    return res;
}
0

Mam pytanie odnośnie tego programu. Jak wyglądało by to w wersji C, krótko to wiem na pewno.
Z góry dzięki :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1