I want to shift elements in one array to right by only changing the index. Also I don't want to use built-in functions
For example, if we have
8,6,5,3,9
Then We will have
9,8,6,5,3
If the array doesn't have enough length. the rest of the elements shift will start from the first index of array.
int index = 0, temp = 0;
int[] myarray = new int[int.Parse(Console.ReadLine())];
for (int i = 0; i < myarray.Length; i++)
{
myarray[i] = int.Parse(Console.ReadLine());
}
for (int i = 0; i < myarray.Length; i++)
{
if (myarray.Length <= i + 5)
{
index = ((i + 5) % 5);
temp = myarray[index];
myarray[index] = myarray[i];
myarray[i] = temp;
}
else
{
temp = myarray[i + 5];
myarray[i + 5] = myarray[i];
myarray[i] = temp;
}
}
this is what i have tried but its not working