- Listing 6.2. A Program That Demonstrates Iterating Through an Array of Five float Values with a Loop
- Code View: Scroll / Show All
- 1: //////////////////////////////////////////////////////
- 2: // Module : array2.cpp
- 3: //
- 4: // Purpose : Shows the simple usage of loops with a
- 5: // one-dimensional array
- 6: //////////////////////////////////////////////////////
- 7:
- 8: #include <iostream.h>
- 9:
- 10: void main()
- 11: {
- 12: // Create an array of five integers
- 13: //
- 14: float num[5];
- 15:
- 16: // Iterate through the array elements, initializing
- 17: // them with float values
- 18: //
- 19: for (int i = 0; i < 5; i++)
- 20: num[i] = i * 2.25f;
- 21:
- 22: // Iterate through the array elements,
- 23: // displaying their values...
- 24:
- 25: for (i = 0; i < 5; i++)
- 26: cout << "num[" << i <<"] == " << num[i] << '\n';
- 27: }