I have the following code:
// Project Euler 16: Sums the digits of 2^1000.
using System;
using System.Numerics;
namespace Project16
{
class Hello
{
static void Main()
{
BigInteger summand = 0;
BigInteger bigInteger = BigInteger.Pow(2, 1000);
string stringbigInteger = bigInteger.ToString();
BigInteger[] stringbigIntegerArray = new BigInteger[stringbigInteger.Length+1];
for (int i = 0; i <= stringbigInteger.Length;i++)
{
//summand += stringbigIntegerArray[i];
stringbigIntegerArray[i] = BigInteger.Parse(stringbigInteger[i]);
Console.WriteLine(stringbigIntegerArray[i]); //outputs 2^1000 at i = 302
}
Console.WriteLine(summand);
Console.ReadKey();
}
}
}
And inside the for loop, where I have stringbigIntegerArray[i], theoretically it should give the first digit to stringbigIntegerArray[0], the second to stringbigIntegerArray[1], and so on. However it gives the entire string to stringbigIntegerArray[301]. How can I fix this?
Aucun commentaire:
Enregistrer un commentaire