1301068321 - TM minggu 1

1301068321 - TM minggu 1 - temp = nums[i]; nums[i] =...

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

View Full Document Right Arrow Icon
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) {
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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 &lt; rows; ++i) { for (register j = 0; j &lt; cols; ++j){ cout &lt;&lt; *(breakfast + i * rows + j) &lt;&lt; ' '&lt;&lt;\n; } } }...
View Full Document

This note was uploaded on 11/14/2011 for the course DDDD h0322 taught by Professor Whoknow during the Spring '11 term at Bina Nusantara University.

Page1 / 2

1301068321 - TM minggu 1 - temp = nums[i]; nums[i] =...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online