给定一个一维数组(10个元素),将数组中最后三个元素调整到开始位置。
temp = a[0];
a[0] = a[7];
a[7] = temp;
temp = a[1];
a[1] = a[8];
a[8] = temp;
temp = a[2];
a[2] = a[9];
a[9] = temp;
如果是第一个换到最后一个,第二个换到倒数第二个,可以这样
int temp = 0;
for(int i = 0; i < 3; i ++){
temp = a[i];
a[i] = a[9 - i];
a[9-i] = temp;
}
加一层for循环,for(j=9;j>=7;j--)