65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
// See https://aka.ms/new-console-template for more information
|
|
using System.Runtime.Versioning;
|
|
//dichiarazione e inizializzazione variabili
|
|
int exit;
|
|
uint input, max, min, media, somma, i, pari;
|
|
const int breakValue = -1;
|
|
max = 0;
|
|
input = 0;
|
|
min = 4294967295; //valore massimo che un uint può assumere
|
|
exit = 0;
|
|
somma = 0;
|
|
i = 0;
|
|
pari = 0;
|
|
|
|
while (exit != breakValue)
|
|
{
|
|
//input e input sanitization
|
|
do
|
|
{
|
|
Console.Write("Inserisci un numero (-1 per terminare): ");
|
|
exit = Convert.ToInt32(Console.ReadLine());
|
|
if (exit != breakValue) //condizione per evitare di conteggiare -1 come valore
|
|
{
|
|
if (exit < breakValue)
|
|
{
|
|
Console.WriteLine("Il numero inserito non può essere minore di -1");
|
|
}
|
|
else
|
|
{
|
|
input = Convert.ToUInt32(exit);
|
|
}
|
|
}
|
|
}
|
|
while (exit < breakValue);
|
|
//inizio calcolo
|
|
if (exit != breakValue)
|
|
{
|
|
// calcolo numero maggiore
|
|
if (input > max){
|
|
max = input;
|
|
}
|
|
|
|
// calcolo numero minore
|
|
if (input < min){
|
|
min = input;
|
|
}
|
|
//calcolo media
|
|
somma = input + somma;
|
|
i++;
|
|
|
|
//conteggio numeri pari
|
|
if (input % 2 == 0){
|
|
pari++;
|
|
}
|
|
}
|
|
}
|
|
// calcolo finale media
|
|
media = somma / i;
|
|
|
|
//output finale
|
|
Console.WriteLine("Risultato:");
|
|
Console.WriteLine("La media vale " +media".");
|
|
Console.WriteLine("Il totale dei numeri inseriti è " +pari".");
|
|
Console.WriteLine("Il numero massimo è " +max + " e il numero minimo è " +min".");
|