FUNZIONAAAAAAH!!!!!!! -Giuseppe Negro
This commit is contained in:
parent
b443abbdf5
commit
5b3038e0b0
16
Program.cs
16
Program.cs
@ -6,8 +6,7 @@ class Program
|
||||
{
|
||||
//dichiarazione e inizializzazione variabili
|
||||
int num;
|
||||
ulong fattoriale, somma, fattorialePrec, fattorialeSupporto;
|
||||
somma=0;
|
||||
ulong fattoriale, somma;
|
||||
//inizio programma
|
||||
//input e input sanitization
|
||||
do{
|
||||
@ -16,26 +15,28 @@ class Program
|
||||
if(num<0){
|
||||
Console.WriteLine("Il numero non può essere negativo");
|
||||
}
|
||||
else if(num>65){
|
||||
else if(num>65){//Gestione dell'overflow, se viene inserito num>65 viene restituito 0, ovviamente è scorretto
|
||||
Console.WriteLine("Il numero inserito è troppo grande");
|
||||
}
|
||||
}
|
||||
while(num<0 || num>65);
|
||||
//gestione caso 0
|
||||
//gestione caso 0 e 1
|
||||
if (num<=1){
|
||||
fattoriale=1;
|
||||
}
|
||||
else{
|
||||
fattoriale=Convert.ToUInt64(num);
|
||||
//ciclo calcolo fattoriale
|
||||
for (int i = 2; i < num; i++){
|
||||
|
||||
for (int i=2; i<num; i++){//inizio a eseguire i prodotti da due in modo da saltare la moltiplicazione per 1
|
||||
somma=0;//resetto somma per inserirci il valore della moltiplicazione intermedia
|
||||
// eseguo "fattoriale * i" con una serie di somme
|
||||
for (int j=0; j<i; j++){
|
||||
somma += fattoriale;
|
||||
somma=somma+fattoriale;
|
||||
}
|
||||
fattoriale=somma; // assegna il risultato della "moltiplicazione" alla variabile fattoriale
|
||||
}
|
||||
//^^^^Per fare questo ciclo ho chiesto aiuto a dei miei amici
|
||||
//Questo di seguito è il ciclo che avevo scritto da solo
|
||||
/*for(i=1; i>num-1; i--){
|
||||
//calcolo fattoriale
|
||||
Console.WriteLine(fattoriale);
|
||||
@ -46,7 +47,6 @@ class Program
|
||||
fattoriale=fattorialeSupporto+fattorialePrec;
|
||||
Console.WriteLine(fattoriale);
|
||||
}*/
|
||||
//fattoriale=fattoriale*Convert.ToUInt64(i);
|
||||
}
|
||||
//output finale
|
||||
Console.Write("Il fattoriale di " +num);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("fattoriale_somma")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c5af8bee6add5fd4b61e1fffe87562d3d712c80f")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b443abbdf5db791bfcd9a131752eac3833d39589")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("fattoriale_somma")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("fattoriale_somma")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@ -1 +1 @@
|
||||
66a3353265c9420f2bd556e0251f61e80f588873e29949abb728f549b15d9ab7
|
||||
7f7c783eb1931c8eb8484e49b862be1fb781fdd57ac0a1fabde9823dca4346e8
|
||||
|
||||
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