Answer to Question #196802 in C++ for youyzj

Question #196802

What are the array contents X after the execution of the following program segment:

 

int  x [ ] = {10, 2, 3, 4, 1 }, i ;

 

  x[ 4 ] = 2 * x[ 3 ] ;

  

  i = 3 ;

  while ( i >= 2 ) 

  {

    if  ( x[ i ] % 2 == 0 )

      x[  i ] = x[ i - 1 ] + 2 ;

    else

      x[  i ] = 11 ;

 

    i -- ;

  }



1
Expert's answer
2021-05-23T08:49:33-0400
using namespace std;


main(void)
{
	int  x[] = {10, 2, 3, 4, 1 }, i ;
	
	x[4] = 2*x[3] ;
    i = 3 ;
	while ( i >= 2 ) 
	{
	    if (x[i]%2 == 0)	x[i] = x[i-1] + 2 ;
	    else				x[i] = 11 ;
	    i -- ;
   }
   cout<<"\n\tArray Contents: ";
   for(i=0;i<sizeof(x)/sizeof(x[0]);i++) cout<<x[i]<<", ";
   return(0);
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog