Upload files to "array"
This commit is contained in:
parent
be6711b2cc
commit
889bc237e9
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue