i am new in programming and for now only practicing with C#. So my problem is: i am trying to separate a number in a digits with array (example: number 12345 in to digits {1,2,3,4,5}). I make some code, here is it:
int num = int.Parse(Console.ReadLine());
int[] digits = new int[3];
int separatedDigit = 0;
for (int i = num; num != 0; i--)
{
digits[i] = num % 10;
num = num / 10;
}
but it shows me error " Index was outside the bounds of the array." I suppose the problem is coming from that "for" part because it starts from position 3 and the array have only 2 (0, 1, 2). I don't know how to fix it, so can someone help me?
digits[12345] = 5, which .net runtime woudn't allow as index '12345' doesn't exist in the array.