0
我有任務做,我設法做的第一部分:陣列反射基本任務
// create an array B that has twice as many elements as A and is
// A forward followed by A in reverse
// if A is {3, 22, -5, 7} then we create B {3, 22, -5, 7, 7, -5, 22, 3}
// array A is declared and the size of A is 'size'
// myapproach
int B[2*size];
int i;
for (i = size; i >-1 ; i--) {
B[i] = A[i];
}
int j; int k;
for (j = 2*size; j>size; i--) {
k = size;
k++;
while (2*size < k) {
B[j] = B[k];
}
}
我的代碼工作的任務的第一部分(B = {3,22,-5, 7,})但我找不出其他的。你能幫我嗎?
你應該只需要2個循環總數和沒有嵌套循環。你也是第一個循環應該從'size-1'而不是'size'。 '[尺寸]'將超出界限。 – twain249