📌  相关文章
📜  国际空间研究组织 | ISRO CS 2015 |问题 72

📅  最后修改于: 2022-05-13 01:58:03.089000             🧑  作者: Mango

国际空间研究组织 | ISRO CS 2015 |问题 72

以下程序的输出是

main()
{
static int x[] = {1,2,3,4,5,6,7,8}
int i;
for (i=2; i<6; ++i)
x[x[i]]=x[i];
for (i=0; i<8; ++i)
printf("%d", x[i]);
} 

(A) 1 2 3 3 5 5 7 8
(B) 1 2 3 4 5 6 7 8
(C) 8 7 6 5 4 3 2 1
(D) 1 2 3 5 4 6 7 8答案:(一)
解释:给定数组:

for (i=2; i<6; ++i)
x[x[i]]=x[i];
For i = 2, x[x[2]] = x[2]  
           = x[3] = 3  // since x[2] = 3
For i = 3, x[x[3]] = x[3]  
           = x[3] = 3  // since x[3] = 3
For i = 4, x[x[4]] = x[4]  
           = x[5] = 5  // since x[4] = 5
For i = 5, x[x[5]] = x[5]  
           = x[5] = 5  // since x[5] = 5
Loop terminates at x = 6, so no changes in index 6 and 7.

新数组:

这个问题的测验