School-Coding-Cpp/array/maggiori_minori_array.cpp

34 lines
994 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
AUTORE: Vichingo455
Leggere un array di interi di 6 posizioni, leggere un ulteriore numero intero, una funzione deve restituire quanti numeri memorizzati nellarray sono inferiori e quanti superiori dellultimo numero letto.
*/
#include <iostream>
#include <array>
#include <vector>
#include <cstdlib>
#define SIZE 6
using namespace std;
void maggioriMinori(int array[], size_t array_size, int numero) {
int maggiori = 0, minori = 0;
for (int i = 0; i < array_size; i++) {
if (array[i] < numero)
minori++;
else if (array[i] > numero)
maggiori++;
}
cout << "I numeri maggiori di " << numero << " sono " << maggiori << ", mentre quelli minori sono " << minori << endl;
}
int main() {
int array[SIZE],numero;
for (int i = 0; i < SIZE; i++) {
cout << "Inserisci il valore: ";
cin >> array[i];
cout << endl;
}
cout << "Inserisci il numero master: ";
cin >> numero;
cout << endl;
maggioriMinori(array, SIZE, numero);
return 0;
}