Upload files to "array"

This commit is contained in:
Vichingo455 2024-12-04 09:38:54 +00:00
parent be6711b2cc
commit 889bc237e9
2 changed files with 47 additions and 0 deletions

25
array/conta_numeri.cpp Normal file
View File

@ -0,0 +1,25 @@
/*
AUTORE: Manuel Vichi
Conta numeri
*/
#include <iostream>
#include <array>
#include <vector>
#include <cstdlib>
using namespace std;
void contaValoriUguali(int array[], size_t array_size) {
for (size_t i = 0; i < array_size; i++) {
int valoreVolte = 0;
for (size_t j = 0; j < array_size; ++j) {
if (array[j] == array[i]) {
valoreVolte++;
}
}
cout << "Il valore " << array[i] << " compare " << valoreVolte << " volte." << endl;
}
}
int main() {
int array[] = {-1, 0, 1, 2, 0, 2, -1, 7, 9};
contaValoriUguali(array,9);
return 0;
}

22
array/somma_positivi.cpp Normal file
View File

@ -0,0 +1,22 @@
/*
AUTORE: Manuel Vichi
Somma dei numeri positivi
*/
#include <iostream>
#include <array>
#include <vector>
#include <cstdlib>
using namespace std;
int sommaPositivi(int array[], size_t array_size) {
int somma = 0;
for (size_t i = 0; i < array_size; i++) {
if (array[i] > 0)
somma += array[i];
}
return somma;
}
int main() {
int array[] = {-1, 0, 1, 2, 3};
cout << "La somma dei valori positivi e': " << sommaPositivi(array,5) << endl;
return 0;
}