Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <format>
- #include <span>
- #include <vector>
- using namespace std;
- int sommatoria(const int v[], size_t dimensione)
- {
- int risultato = 0;
- for (size_t i = 0; i < dimensione; i++) risultato += v[i];
- return risultato;
- }
- void reset(span<int> v)
- {
- for (int &n : v) n = 0;
- }
- int sommatoria_con_span(span<const int> v)
- {
- int risultato = 0;
- for (int n : v) risultato += n;
- return risultato;
- }
- void stampa(span <const int> v)
- {
- for (int n : v) cout << n << " ";
- cout << endl;
- }
- int main()
- {
- int valori[]{ 20, 45, 71, 100, -87, 22, 9 };
- cout << format("La sommatoria vale: {}\n", sommatoria(valori, 3));
- cout << format("La sommatoria vale: {}\n", sommatoria_con_span(valori));
- //reset(valori);
- //stampa(valori);
- span<const int> v{ valori };
- cout << format("Primo elemento span: {}, ultimo elemento: {}\n", v.front(), v.back());
- stampa(v.subspan(2, v.size()-4));
- stampa(v.first(3));
- stampa(v.last(3));
- cout << v[0] << endl;
- vector<int> vect{ 4,67,89,11 };
- stampa(vect);
- span<int> span{ vect };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement