User Tools

Site Tools


cs509:arrayfromkeyboard

Array example from class, 3/6/13

/*
Write a program that will fill an array a with 20 values of type int read in
from the keyboard.
*/

#include <iostream>

using namespace std;

int main()
{
    // array size in a constant
    const int asize = 20;

    // declare array
    int a[ asize ] = { 0 };

    // loop to get 20 values from keyboard and fill array
    for ( int i = 0; i < asize; i++ ) {
        cout << "\n Enter value for array element " << i << ": ";

        cin >> a[ i ];
    }

}
cs509/arrayfromkeyboard.txt · Last modified: 2013/03/07 07:48 by jchung

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki