Answer: BigInteger class resides in the System.Numerics namespace.It helps in representing any large integer without any loss of precision. It has been introduced earlier in dotnet framework 3.5 but was removed. However, it is again back in framework 4.0.
Example: To find the factorial of 100.
static void Main(string[] args)
{
Console.Write("Factorial of hundred is : ");
HundredFactorial();
Console.Read();
}
private static void HundredFactorial()
{
BigInteger number = 100;
BigInteger fact = 1;
for (; number-- > 0; ) fact *= number+1;
Console.WriteLine(fact);
}
Output
Factorial of hundred is : 93326215443944152681699238856266700490715968264381621
46859296389521759999322991560894146397615651828625369792082722375825118521091686
4000000000000000000000000
It exposes some methods as
a) GreatestCommonDivisor [ BigInteger.GreatestCommonDivisor(12, 24) ]
b) Compare [ BigInteger.Compare(num1, num2) ]
c) Parse [ BigInteger.Parse("10000000") ]
d) Negate [ BigInteger.Negate(100) ]
etc.
Asked In: Many Interviews |
Alert Moderator