Declaring an Array and Using a Loop to Initialize the Array's Elements - C++ Data Type

C++ examples for Data Type:Array

Description

Declaring an Array and Using a Loop to Initialize the Array's Elements

Demo Code

#include <iomanip>
#include <iostream>

int main(int argc, const char *argv[]) {
    int n[10];//from  ww  w.  j av  a2  s .c om

    for (int i = 0; i < 10; ++i) {
        n[i] = 0;
    }

    std::cout << "Element" << std::setw(13) << "Value" << std::endl;

    for (int i = 0; i < 10; ++i) {
        std::cout << std::setw(7) << i << std::setw(13) << n[i] << std::endl;
    }
    return 0;
}

Result


Related Tutorials