1.1.12 #
解答 #
第一个循环初始化数组 {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
第二个循环用相应位置的值作为下标取值,例如:a[0] = a[a[0]] = a[9] = 0
最后结果为:0,1,2,3,4,4,3,2,1,0
代码 #
var a = new int[10];
for (var i = 0; i < 10; i++)
{
a[i] = 9 - i;
}
// a[10] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
for (var i = 0; i < 10; i++)
{
a[i] = a[a[i]];
}
// a[0] = a[9] = 0; a[1] = a[8] = 1; a[2] = a[7] = 2;......
for (var i = 0; i < 10; i++)
{
Console.WriteLine(a[i]);
}