School-Coding-Cpp/sfusi/array6posizioni - Copia.cpp

52 lines
965 B
C++
Raw Permalink 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.

/*
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>
#define DIM 6
using namespace std;
int supInf(int arr[], size_t size, int num, int sup , int inf){
for(size_t i = 0; i<size; i++){
if(arr[i] > num){
sup++;
}
else if(arr[i] < num){
inf++;
}
}
cout << endl << "Ci sono " << sup << " numeri maggiori a quello che hai inserito"<< endl;
cout << "Ci sono "<< inf << " numeri inferiori a quello che hai inserito";
}
int main(void){
int bobby[DIM];
int superiore, inferiore;
int x;
cout <<"Inserisci un numero: ";
cin >> x ;
for(size_t i = 0; i<DIM; i++){
cout << "Inserisci valore " << i+1 << ":"<< endl;
cin >> bobby[i];
}
supInf(bobby, DIM, x, superiore, inferiore);
}