Zebra0.com

cpp arraysInput 3 numbers

Input 3 numbers

When variables have the same function in a program, it is often more efficient to use an array.

The program below reads in three numbers, and then prints them.

The statement double num[3]; allocates space in memory for three decimal numbers. The three numbers are referred to as num[0], num[1], and num[2].

array

The number inside brackets is the subscript or index. The subscripts always start with 0.

Once a variable is declared as an array, the subscript must be included to refer to the elements.

One of the advantages of an array is that the subscript can be a variable. A for loop can be used to read in an array of numbers or print them out.