Opzione 5
This commit is contained in:
parent
448c8e2782
commit
33b62a3e37
68
Program.cs
68
Program.cs
@ -10,14 +10,24 @@ class Program
|
||||
bool opzione1=false;
|
||||
string input="";
|
||||
int i=0;
|
||||
int p=0;
|
||||
int d=0;
|
||||
int numeri=0;
|
||||
int somma=0;
|
||||
int media=0;
|
||||
const int dimensione=5;
|
||||
const int divisibile=7;
|
||||
int[] insieme1=new int[dimensione];
|
||||
for (; i<dimensione; i++){
|
||||
insieme1[i]=0;
|
||||
for (int j=0; j<dimensione; j++){
|
||||
insieme1[j]=0;
|
||||
}
|
||||
int[] pari=new int[dimensione];
|
||||
for (int j=0; j<dimensione; j++){
|
||||
pari[j]=0;
|
||||
}
|
||||
int[] dispari=new int[dimensione];
|
||||
for (int j=0; j<dimensione; j++){
|
||||
dispari[j]=0;
|
||||
}
|
||||
|
||||
|
||||
@ -55,7 +65,7 @@ class Program
|
||||
i++;
|
||||
}
|
||||
while (input!="q" && i<dimensione);
|
||||
opzione1=true;
|
||||
opzione1=true;//traccia eseguita
|
||||
Pausa();
|
||||
break;
|
||||
case 2:
|
||||
@ -103,6 +113,58 @@ class Program
|
||||
break;
|
||||
case 5:
|
||||
Console.Clear();
|
||||
//reset per permettere esecuzioni consecutive
|
||||
i=0;
|
||||
p=0;
|
||||
d=0;
|
||||
for (int j=0; j<dimensione; j++){
|
||||
pari[j]=0;
|
||||
}
|
||||
for (int j=0; j<dimensione; j++){
|
||||
dispari[j]=0;
|
||||
}
|
||||
//inserimento e logica
|
||||
do{
|
||||
Console.Write("Inserire un numero, massimo " +dimensione*2+ " numeri ([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
|
||||
//catch del tentativo di indirizzare fuori dall'array
|
||||
if (p>=dimensione){
|
||||
Console.WriteLine("E' stato inserito il numero massimo di numeri pari, riprovare.");
|
||||
}
|
||||
else if (d>=dimensione){
|
||||
Console.WriteLine("E' stato inserito il numero massimo di numeri dispari, riprovare.");
|
||||
}
|
||||
//assegnazione negli array
|
||||
else {
|
||||
if (input!="q"){//non si è interrotto l'inserimento
|
||||
if(Convert.ToInt32(input)%2==0){//se pari
|
||||
pari[p]=Convert.ToInt32(input);
|
||||
p++;
|
||||
}
|
||||
else{
|
||||
dispari[d]=Convert.ToInt32(input);
|
||||
d++;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
while (input!="q" && i<dimensione*2);
|
||||
|
||||
//output
|
||||
Console.WriteLine("Numeri pari:");
|
||||
for (int j=0; j<dimensione; j++){
|
||||
if (pari[j]!=0){
|
||||
Console.WriteLine("Elemento " +j+ ": " +pari[j]);
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Numeri dispari:");
|
||||
for (int j=0; j<dimensione; j++){
|
||||
if (dispari[j]!=0){
|
||||
Console.WriteLine("Elemento " +j+ ": " +dispari[j]);
|
||||
}
|
||||
}
|
||||
Pausa();
|
||||
break;
|
||||
case 6:
|
||||
Console.Clear();
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("array_funzioni")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9ff0e1a8226cc5b25f24ce9ecb78fd21b9e6a4f9")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+448c8e2782222a90844e546ff8e33e74a66a7613")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("array_funzioni")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("array_funzioni")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@ -1 +1 @@
|
||||
8c7acecc9ea75f0d051e07c4944936c0a6ab1b23f4d54bf8ac33fca938367ee4
|
||||
4f72e79b558fa8093fff6ea16dac313554ce036707aeaa78401514a342a7c390
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user