







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








Page 1 Problem Exercises
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'
Page 2 e) for (int i = 0; i < 11; i++) { b[i] = a[i]; } f) // Assume that 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]; } }
Page 4 f) t[0][2], t[1][2] g) t[0][1] = 0; h) t[0][0] = 0; t[0][1] = 0; t[0][2] = 0; t[1][0] = 0; t[1][1] = 0; t[1][2] = 0; i) for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) t[i][j] = 0; } } j) for (int r = 0; r < 2; r++) { for (int c = 0; c < 3; c++) { cin >> t[r][c] ; } } or cin >> t[0][0] >> t[0][1] >> t[0][2]; cin >> t[1][0] >> t[1][1] >> t[1][2]; k) int smallest = t[0][0]; for (int r = 0; r < 2; r++) { for (int c = 0; c < 3; c++) { if (t[r][c] < smallest) { smallest = t[r][c]; } } } cout << smallest;
Page 5 l) cout << t[0][0] << ' ' << t[0][1] << ' ' << t[0][2] <<'\n'; m) Array โtโ does not contain a fourth column. n) cout << " 0 1 2 \n"; for (int r = 0; r < 2; r++) { cout << r << ' '; for (int c = 0; c < 3; c++) { cout << t[r][c] << " "; } cout << '\n'; } o) int total = 0; for (int n = 0; n < 2; n++) { total += t[n][1]; }
Page 7
order in which they are set to zero by the following program segment: for (int row = 0; row < 3; row++) { for (int column = 0; column < 5; column++) { sales[row][column] = 0; } } Answer: sales[0][0], sales[0][1], sales[0][2], sales[0][3], sales[0][4], sales[1][0], sales[1][1], sales[1][2], sales[1][3], sales[1][4], sales[2][0], sales[2][1], sales[2][2], sales[2][3], sales[2][4]
Page 8
fills the array dArr with values such that each element of dArr is the corresponding value of array sArr rounded up to the next multiple of 10. Thus, 1 round to 10, 10 stays as 10, 11 rounds to 20, 28 rounds to 30, and so on... #include
Page 10
function that fills the array dArr with values such that each element of dArr is the corresponding value of array sArr minus the minimum value of array sArr. Minimum Value sArr dArr 14 3 21 6 43 64 23 96 10 13 8 7 #include
Page 11 }
Page 13 Sample output: