Working with a vector container to add integer value - C++ STL

C++ examples for STL:vector

Description

Working with a vector container to add integer value

Demo Code

#include <iostream>
#include <iomanip>
#include <vector>

int main()//  w ww.  j a  v a  2s.  c  o  m
{
  std::vector<int> values;
  // Add element values 1 to 100
  for (int i {1}; i <= 100; ++i)
    values.push_back(i);

  int count {};                              // Number of output values
  int perline {8};                           // Number output perline

  for (auto value : values){
    if ((value % 7) == 0 || (value % 13) == 0)
       continue;
    std::cout << std::setw(5) << value;
    if ((++count % perline) == 0)
       std::cout << "\n";
  }
  std::cout << std::endl;
}

Result


Related Tutorials