The code bellow is supposed to return the value of PI in an array of a given length.
Once i run this code the console shows: 0000System.Int32[].
Console.WriteLine(newPi[i]);
should print out 3141 which is the newPi
.
Bellow is where i got so far:
namespace MakePi
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(MakePi(4));
Console.ReadLine();
}
public static int[] MakePi(int n)
{
double pi = Math.PI;
string piString = pi.ToString().Remove(1, 1);
int[] newPi = new int[n];
for (int i = 0; i < n; i++)
{
Console.Write(newPi[i]);
}
return newPi;
}
}
}
I think the mistake is at int[] newPi = new int[n];
but i still got some difficulties fixing it, could someone help?