Loop through a given array 7 times and print the following output:
int[] arr = { 9, 2, 7, 4, 6, 1, 3 };
92746 13927 46139 27461 39274 61392 74613
And this is my code so far:
static void Main(string[] args)
{
int[] arr = { 9, 2, 7, 4, 6, 1, 3 };
int rotate = 7;
int printsize = 5;
int addsize = 0;
int startsize = 0;
for (int i = 0; i < rotate; i++)
{
Print(arr, printsize, ref addsize, ref startsize);
}
}
static void Print(int[] arr, int printsize,ref int addsize, ref int startsize)
{
int n = (arr.Length - 1);
int loop = 0;
for (int j = startsize; j <= (printsize + addsize); j++)
{
Console.Write(arr[j]);
if (loop == 4)
{
startsize = j + 1;
addsize = (n) - j;
break;
}
if (j == n)
{
addsize = 0;
j = -1;
printsize = printsize - (loop + 1);
}
loop = loop + 1;
}
Console.WriteLine();
}