0% found this document useful (0 votes)
39 views3 pages

Cuando Esta Escribir: Console Console Console

The document contains code examples for calculating the factorial of a user-input number in C#. It shows the initial code with explanations of the variables and logic. It then provides two alternative implementations: one using shorthand assignments like F *= I and I++, and another using a do-while loop instead of a regular while loop to iterate through the calculation. The overall purpose is to demonstrate different ways to write the factorial function in C#.

Uploaded by

Melissa Sue
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views3 pages

Cuando Esta Escribir: Console Console Console

The document contains code examples for calculating the factorial of a user-input number in C#. It shows the initial code with explanations of the variables and logic. It then provides two alternative implementations: one using shorthand assignments like F *= I and I++, and another using a do-while loop instead of a regular while loop to iterate through the calculation. The overall purpose is to demonstrate different ways to write the factorial function in C#.

Uploaded by

Melissa Sue
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Cuando esta escribir

static void Main(string[] args)


{
int I, N, F;
System.Console.Write("Ingresa el numero");
N = int.Parse(System.Console.ReadLine());
if (N <= 1)
System.Console.Write("1");
else
{
F = 1;
I = 2;
while (I<=N)
{
F = F * I;
I = I + 1;

}
System.Console.WriteLine("el factorial de " + N + " es " + F);

System.Console.ReadLine();
}
}
}

Cuando es F= 1
static void Main(string[] args)
{
int I, N, F;
System.Console.Write("Ingresa el numero");
N = int.Parse(System.Console.ReadLine());
if (N <= 1)
F = 1;
else
{
F = 1;
I = 2;
while (I <= N)
{
F = F * I;
I = I + 1;

}
}
System.Console.WriteLine("el factorial de " + N + " es " + F);
System.Console.ReadLine();
}
}
}

Otra forma

static void Main(string[] args)


{
int I, N, F;
System.Console.Write("Ingresa el numero");
N = int.Parse(System.Console.ReadLine());
if (N <= 1)
F = 1;
else
{
F = 1;
I = 2;
while (I <= N)
{
F *= I; // F = F * I ;
I ++; // I = I + 1 ;

}
System.Console.WriteLine("el factorial de " + N + " es " + F);
System.Console.ReadLine();
}
}
}
Con ‘’do ‘’

static void Main(string[] args)


{
int I, N, F;
System.Console.Write("Ingresa el numero");
N = int.Parse(System.Console.ReadLine());
if (N <= 1)
F = 1;
else
{
F = 1;
I = 2;
do

{
F *= I; // F = F * I ;
I++; // I = I + 1 ;

}
while (I <= N);

}
System.Console.WriteLine("el factorial de " + N + " es " + F);
System.Console.ReadLine();
}
}
}

You might also like