{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

1301068321 - TM minggu 1

# 1301068321 - TM minggu 1 - temp = nums[i nums[i = nums[size...

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

David Tanady 1301068321 04 PBH Sistem Komputer 1. Define two functions which, respectively, input values for the elements of an array of reals and output the array elements: void ReadArray (double nums[], const int size); void WriteArray (double nums[], const int size); void ReadArray (double nums[], const int size) { for (register i = 0; i < size; ++i) { cout << "nums[" << i << "] = "; cin >> nums[i]; } } void WriteArray (double nums[], const int size) { for (register i = 0; i < size; ++i) cout << nums[i] << '\n'; } 2. Define a function which reverses the order of the elements of an array of reals: void Reverse (double nums[], const int size); void Reverse (double nums[], const int size) { double temp; for (register i = 0; i < size/2; ++i) {

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: temp = nums[i]; nums[i] = nums[size - i - 1]; nums[size - i - 1] = temp; } } 3. The following table specifies the major contents of four brands of breakfast cereals. Define a two-dimensional array to capture this data: Fiber Sugar Fat Salt Cereal A 12g 25g 16g 0.4g Cereal B 22g 4g 8g 0.3g Cereal C 28g 5g 9g 0.5g Cereal D 32g 7g 2g 0.2g double breakfast[4] = { { 12, 25, 16, 0.4 }, { 22, 4, 8, 0.3 }, { 28, 5, 9, 0.5 }, { 32, 7, 2, 0.2 } }; void WriteContents (const double *breakfast, const int rows, const int cols) { for (register i = 0; i < rows; ++i) { for (register j = 0; j < cols; ++j){ cout << *(breakfast + i * rows + j) << ' '<<’\n’; } } }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

1301068321 - TM minggu 1 - temp = nums[i nums[i = nums[size...

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

View Full Document
Ask a homework question - tutors are online