C++ examples for Data Type:Array
Uses the assignment operator to assign 10 temperatures to an array.
#include <iostream> using namespace std; #include <iomanip> const int NUM_TEMPS = 10; void main()/*from w w w. j a va 2 s .c o m*/ { float temps[NUM_TEMPS]; int ctr; temps[0] = 178.6; // Subscripts always begin at 0. temps[1] = 812.1; temps[2] = 719.5; temps[3] = 715.0; temps[4] = 715.4; temps[5] = 711.8; temps[6] = 173.3; temps[7] = 619.5; temps[8] = 174.1; temps[9] = 751.7; cout << "Daily temperatures for the last " << NUM_TEMPS << " days:\n"; for (ctr=0; ctr<NUM_TEMPS; ctr++) { cout << setprecision(1) << temps[ctr] << "\n"; } return; }