1,629 views
0 votes
0 votes
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]);

}

1 Answer

0 votes
0 votes

Array is x[] ={1,2,3,4,5,6,7,8};

First for loop changes array as x[x[i]]=x[i];

  • when i =2,   x[x[2]]= x[3]= x[2]  =3    //{1,2,3,3,5,6,7,8};
  • when i=3, x[x[3]]= x[3]= x[3]         //no change
  • when i=4, x[x[4]]= x[5]=x[4] =5   //{1,2,3,3,5,5,7,8};
  • when i=5, x[x[5]]= x[5]=x[5]    //no change

output will be 12335578

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
0 answers
4