Opzione 2
This commit is contained in:
parent
3efdd8911e
commit
be372a37e8
70
Program.cs
70
Program.cs
@ -1,16 +1,19 @@
|
||||
namespace ripasso3;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace ripasso3;
|
||||
|
||||
class Program {
|
||||
const int minDimensione = 0;
|
||||
const int maxDimensione = 100;
|
||||
const int minNumero = 0;
|
||||
const int maxNumero = 100;
|
||||
static void Main(string[] args) {
|
||||
int scelta;
|
||||
int[] array = null;
|
||||
int[] array = null; //Tecnica Segreta™ dei puntatori
|
||||
bool opzione1 = false;
|
||||
|
||||
do {
|
||||
Console.Clear();
|
||||
Console.WriteLine("Scegliere un'opzione:");
|
||||
Console.WriteLine("1. Crea un'insieme di numeri tra " + minDimensione + " e " + maxDimensione);
|
||||
Console.WriteLine("1. Crea un'insieme di numeri tra " + minNumero + " e " + maxNumero);
|
||||
Console.WriteLine("2. Mostra il maggiore e il minore");
|
||||
Console.WriteLine("3. Calcolo media");
|
||||
Console.WriteLine("0. Esci");
|
||||
@ -23,20 +26,26 @@ class Program {
|
||||
Console.Clear();
|
||||
break;
|
||||
case 1:
|
||||
opzione1 = false;
|
||||
Console.Clear();
|
||||
array = CreaArray();
|
||||
StampaArray(array);
|
||||
//StampaArray(CreaArray());
|
||||
opzione1 = true;
|
||||
Pausa();
|
||||
break;
|
||||
case 2:
|
||||
Console.Clear();
|
||||
|
||||
if(opzione1){
|
||||
MaxMin(array);
|
||||
}
|
||||
else{
|
||||
Console.WriteLine("È necessario eseguire l'opzione 1 prima di poter eseguire questa");
|
||||
}
|
||||
Pausa();
|
||||
break;
|
||||
case 3:
|
||||
Console.Clear();
|
||||
|
||||
Media();
|
||||
Pausa();
|
||||
break;
|
||||
|
||||
@ -81,7 +90,7 @@ class Program {
|
||||
Console.Write("Inserire un numero ([q] per uscire): ");
|
||||
input=Console.ReadLine(); //non posso ancora fare il catch dell'eccezione se viene inserito un qualcosa che non sia un numero o q
|
||||
if(input!="q"){
|
||||
if(Convert.ToInt32(input) >= minDimensione && Convert.ToInt32(input) <= maxDimensione){
|
||||
if(Convert.ToInt32(input) >= minNumero && Convert.ToInt32(input) <= maxNumero){
|
||||
ritorno[i]=Convert.ToInt32(input);
|
||||
i++;
|
||||
}
|
||||
@ -97,11 +106,46 @@ class Program {
|
||||
|
||||
return ritorno;
|
||||
}
|
||||
static void StampaArray(int[] p_insieme) {
|
||||
for (int j = 0; j < p_insieme.Length; j++) {
|
||||
if (p_insieme[j] != -1) {
|
||||
Console.WriteLine("Elemento " + j + ": " + p_insieme[j]);
|
||||
static void StampaArray(int[] p_array) {
|
||||
for (int j = 0; j < p_array.Length; j++) {
|
||||
if (p_array[j] != -1) {
|
||||
Console.WriteLine("Elemento " + j + ": " + p_array[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
static void MaxMin(int[] p_array){
|
||||
int temp = -1, max = maxNumero, min = minNumero;//temp è -1 perché è il valore di default dell'array quando è vuoto, e qualsiasi valore inserito sarà maggiore di questo
|
||||
|
||||
for (int i = 0; i < p_array.Length; i++){
|
||||
if (p_array[i] != -1){
|
||||
if(p_array[i] == maxNumero){//se ho già trovato il massimo valore inseribile
|
||||
max = p_array[i];
|
||||
break;//interrompo subito la ricerca
|
||||
}
|
||||
if (p_array[i] > temp){
|
||||
max = p_array[i];
|
||||
}
|
||||
}
|
||||
temp = p_array[i];
|
||||
}
|
||||
|
||||
temp = maxNumero;//reset della variabile temporanea di appoggio, così che qualsiasi valore sia minore di questo
|
||||
|
||||
for (int i = 0; i < p_array.Length; i++){
|
||||
if (p_array[i] != -1){
|
||||
if(p_array[i] == minNumero){//se ho già trovato il minimo valore inseribile
|
||||
min = p_array[i];
|
||||
break;//interrompo subito la ricerca
|
||||
}
|
||||
if (p_array[i] < temp){
|
||||
min = p_array[i];
|
||||
}
|
||||
}
|
||||
temp = p_array[i];
|
||||
}
|
||||
Console.WriteLine("Il valore minimo è " + min + " mentre il valore massimo è " + max);
|
||||
}
|
||||
static void Media(){
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("ripasso3")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+086b21dd793eaa17d118504d46c1e2453b3e6c2e")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3efdd8911e1703151775a922d9fb8d6b4b80d05d")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("ripasso3")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("ripasso3")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@ -1 +1 @@
|
||||
ac2921e05374effe4e870836228f7bfb3b5cb46f2517248564fe24fc495f7806
|
||||
d73a50dabbb49d991ace67ec8edcaa15cf29464cf2168b7c8fae774cd9acccb0
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user