Question

5. (2 points) What are the values in array x after the following code executes (list all of the elements of the array)? CS111
0 0
Add a comment Improve this question Transcribed image text
Answer #1

X contains the following elements after the execution of the code:

x={2.0 , -1.0 , 3.0 , -2.0 , 4.0 , -3.0}

As the length of the array is 6

Loop will execute less then 6 that is i value will execute till 5: i<x.length: i<6

Explanation: Every element the array depends on this step x[i]=x[i-1]+x[i]

x[0]=2.0

For value of i=1

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

x[1] = 2.0 + -3.0

x[1] = -1.0

********************************

For value of i=2

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

x[2] = -1.0 + 4.0

x[2] = 3.0

*******************************

For value of i=3

x[3] = x[3-1] + x[3] ;

x[3] = 3.0+ -5.0

x[3] = -2.0

******************************

For value of i=4

x[4] = x[4-1] + x[4] ;

x[4] = -2.0 + 6.0

x[4] = 4.0

*****************************

For value of i=5

x[5] = x[5-1] + x[5] ;

x[5] = 4.0 + -7.0

x[5] = -3.0

******************************

C: \Users\suguna\Desktop>java loop 2.0 1.0 3.0 2.0 4.0 3.0

Add a comment
Know the answer?
Add Answer to:
5. (2 points) What are the values in array x after the following code executes (list...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT