{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Problem Exercises Chapter 04

# Problem Exercises Chapter 04 - Chapter 4 Exercices 1 1...

This preview shows pages 1–3. Sign up to view the full content.

Chapter 4 Exercices 1 1) Write C++ statements to accomplish each of the following: a) Display the value of the seventh element of character array f. b) Input a value into element 4 of single floating-point array b. c) Initialize each of the 5 elements of single integer array g to 8. d) Total and print the elements of floating-point array c of 100 elements. e) Copy array “a” into the first portion of array “b”. Assume that the two arrays have the following declaration: double a[11], b[34]; f) Determine and print the smallest and largest values contained in 99- element floating-point array w. Answer : a) cout << f[6] << '\n'; b) cin >> b[3]; c) int g[5]={8,8,8,8,8}; or for ( int j = 0; j < 5; ++j) g[j] = 8; d) float total = 0; for ( int k = 0; k < 100; ++k) { total += c[k]; cout << c[k] << '\n' } cout << total << '\n' e) for ( int i = 0; i < 11; ++i) b[i] = a[i]; f) //assume all variables are declared and initialized for ( int j = 0; j < 99; ++j) if (w[j] < smallest) smallest = w[j]; else if (w[j] > largest) largest = w[j];

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Chapter 4 Exercices 2 2) Consider a 2-by-3 integer array “t”. a) Write a declaration for “t”. b) How many rows does “t” have? c) How many columns does “t” have? d) How many elements does “t” have? e) Write the names of all elements in the second row of “t”. f) Write the names of all the elements in the third column of “t”. g) Write a single statement that sets the element of “t” in row 1 and column 2 to zero. h) Write a series of statements that initialize each element of “t” to zero. Do not use a loop. i) Write a nested " for " structure that initializes each element of the double array "t" to zero. j) Write a statement that inputs the values of the elements of “t” from the terminal. k) Write a series of statements that determine and print the smallest value in array “t”. l) Write a statement that displays the elements of the first row of “t”. m) Write a statement that totals the elements of the fourth column of “t”. n) Write a series of statements that prints the array t in neat, tabular format. List the column subscripts as headings across the top and list the row subscripts at the left of each row.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 13

Problem Exercises Chapter 04 - Chapter 4 Exercices 1 1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online