October 10, 2014

One Algorithm per day (C#): Create a new array which the started index Num = array.Count() - n

//Ex: int[10] array1;
// n = 2;
// => Num = 8;
// if n = 12;
// => Num = 8;

List<int> Nums = new List<int>();
List<int> result = new List<int>();

int num = 10;
int n = 12;

for(int i = 0; i < num; i++)
 Nums.Add(i+1);

int m = num;
int j = num - (n % num);

while( m > 0)
{
 result.Add(Nums[j]);
 m--;
 j++;
 j = j % num;
}

foreach(int i in result)
 Console.WriteLine(i);

No comments: