×
Get Full Access to C++ For Everyone - 2 Edition - Chapter 6 - Problem R6.2
Get Full Access to C++ For Everyone - 2 Edition - Chapter 6 - Problem R6.2

×

# Consider the following array:int a[] = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 };What is the

ISBN: 9780470927137 356

## Solution for problem R6.2 Chapter 6

C++ for Everyone | 2nd Edition

• Textbook Solutions
• 2901 Step-by-step solutions solved by professors and subject experts
• Get 24/7 help from StudySoup virtual teaching assistants

C++ for Everyone | 2nd Edition

4 5 1 249 Reviews
19
5
Problem R6.2

Consider the following array:int a[] = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 };What is the value of total after the following loops complete?a.int total = 0;for (int i = 0; i < 10; i++) { total = total + a[i]; }b.int total = 0;for (int i = 0; i < 10; i = i + 2) { total = total + a[i]; }c.int total = 0;for (int i = 1; i < 10; i = i + 2) { total = total + a[i]; }d.int total = 0;for (int i = 2; i <= 10; i++) { total = total + a[i]; }e.int total = 0;for (int i = 0; i < 10; i = 2 * i) { total = total + a[i]; }f. int total = 0;for (int i = 9; i >= 0; i--) { total = total + a[i]; }g.int total = 0;for (int i = 9; i >= 0; i = i - 2) { total = total + a[i]; }h.int total = 0;for (int i = 0; i < 10; i++) { total = a[i] - total; }

Step-by-Step Solution:
Step 1 of 3

BE 1500 – Fall 2016 Quiz 5 1. Write a script that produces the following output. The script should iterate from 1 to 9 to produce the expressions on the left, perform the operation to get the results shown on the right, and print the output below. Your code needs to use either str2num or num2str or both and must utilize at least one loop. 1 x 8 + 1 = 9 12 x 8 + 2 = 98 123 x 8 + 3 = 987 1234 x 8 + 4 = 9876 12345 x 8 + 5 = 98765 123456 x 8 + 6 = 987654 1234567 x 8 + 7 = 9876543 12345678 x 8 + 8 = 98765432 123456789 x 8 + 8 = 987654321 k='123456789';%Initialize my string m=length(k);%Define my stopping point for i=1:m %Loop through the string l=str2num(k(1:i));%Convert string to numbers a=l*8+i; fprintf('%i * %i + %i = %i \n',l,8,i,a)%output end 4 points  1 point for comments  0.5 for k=’123456789’  0.5 for for loop  1 point for l=str2num(k(1:i))  1 point for fprintf 2. Create a script that prompts the user to input a series of data points (this needs to be arbitrary; the number of data points could change depending on the order of the polynomial). Create a matrix (A) based off Newton’s interpolating polynomial. Using the backslash operator (Ax=b  x=A\b) determine the coefficients for the polynomial. You may only use the built-in functions input, disp, zeros, and ones. A=input('Number of data points '); for i=1:A x(i)=i

Step 2 of 3

Step 3 of 3

## Discover and learn what students are asking

#### Related chapters

Unlock Textbook Solution