C# Calcular Factorial

Iniciado por Vuls, Agosto 26, 2020, 11:09:32 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Agosto 26, 2020, 11:09:32 PM Ultima modificación: Agosto 26, 2020, 11:36:48 PM por Gabriela
Hola, necesito calcular el factorial de numeros grandes pero al llegar al 170 me retorna el signo infinito, como puedo solucionar eso (Probe en excel y lo calcula sin problema)

Hola,

Necesitas de unas clases especiales para manejar tal cantidad de datos.
Me parece que en C# está BigInteger

Agregas Referencia a :

Código: csharp
System.Numerics.BigInteger


Código: csharp


using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Numerics.BigInteger;

namespace asdadsa
{
    class Program
    {
        static void Main(string[] args)
        {
            var bi = new BigInteger(1);
            var fact = 170;
            for (var i = 1; i <= fact; i++)
            {
                bi *= i;
            }
           

        }
    }
}